在ie中,css是可以嵌入js表达式的,可以在css类中定义,但是将含有表达css类从dom对象中移除,样式表达式是不会失效的。
经过研究找到了答案,需要使用js调用style对象的removeexpression()方法才可去除。
下面是方法的说明:
语法
bsuccess = object.removeexpression(spropertyname)
参数
spropertyname required. string that specifies the name of the property from which to remove an expression.
返回值
returns one of the following possible values:
true the expression was successfully removed.
false the expression was not removed.
下面给出一个实用例子:利用样式限制图片最大宽度,通过一个按钮切换实际大小与缩放大小。
css类,作用:限制图片的最大宽度,超出指定宽度等比缩小。
css代码
.wrap { border:none; max-width:730px; height:auto; width:expression(this.width>730?730px:true);/*ie6补丁*/ }
图片
html代码
切换按钮
html代码
[原始大小]
js代码(需要jquery)
java代码
function showorigin(){ $('#chart_img').toggleclass(chart); if($('#chart_img').attr(class)){ $('#imgctr').text([原始大小]); }else{ $('#imgctr').text([缩放大小]); $('#chart_img')[0].style.removeexpression('width'); /*ie6补丁*/ } }
这个事例只有在ie6中才能体现removeexpression()的作用,ie7以上是不需要的。