六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 145|回复: 0

去掉CSS中的表达式Expression

[复制链接]

升级  70%

5

主题

5

主题

5

主题

童生

Rank: 1

积分
35
 楼主| 发表于 2013-2-7 22:26:50 | 显示全部楼层 |阅读模式
 在IE中,CSS是可以嵌入js表达式的,可以在CSS类中定义,但是将含有表达CSS类从DOM对象中移除,样式表达式是不会失效的。
经过研究找到了答案,需要使用js调用style对象的removeExpression()方法才可去除。
下面是方法的说明:
 
语法
bSuccess = object.removeExpression(sPropertyName)
参数
sPropertyNameRequired. String that specifies the name of the property from which to remove an expression.
返回值
Returns one of the following possible values:
trueThe expression was successfully removed.
falseThe expression was not removed.
下面给出一个实用例子:利用样式限制图片最大宽度,通过一个按钮切换实际大小与缩放大小。
 
CSS类,作用:限制图片的最大宽度,超出指定宽度等比缩小。
.wrap {border:none;max-width:730px;height:auto;width:expression(this.width>730?"730px":true);/*ie6补丁*/} 
 图片<img>
<img id="chart_img" class="chart" src="bond_big.jpg"/> 
切换按钮
<span id="imgctr" style="cursor: pointer;display: block" >[原始大小]</span> 
js代码(需要jQuery)
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以上是不需要的。
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表