CSS里面可以执行JS代码吗?
CSS里面可以执行JS代码吗?程序里很多地方都使用了当前这个样式,现在需要根据具体情况判断。我不想每个地方都改,那样工作量太大,能不能在在CSS里执行一段JS进行判断?
------解决方案--------------------.btn{
width: 50px;
border: 1px solid #F6FAEE;
BEHAVIOR: url(include/btn.htc);
}
类似这样的写。
以下是btn.htc,供参考
<PUBLIC:COMPONENT>
<PUBLIC:ATTACH EVENT= "onmouseover " ONEVENT= "onit() " />
<PUBLIC:ATTACH EVENT= "onmousedown " ONEVENT= "upit() " />
<PUBLIC:ATTACH EVENT= "onmouseup " ONEVENT= "onit() " />
<PUBLIC:ATTACH EVENT= "onmouseout " ONEVENT= "init() " />
<PUBLIC:ATTACH EVENT= "onload " ONEVENT= "init() " FOR= "window " />
<SCRIPT>
function init() {
runtimeStyle.border= "1px solid #F6FAEE ";
runtimeStyle.cursor= "hand ";
runtimeStyle.width= "60px ";
}
function onit() {
runtimeStyle.borderRight= "1px solid #60A239 ";
runtimeStyle.borderLeft= "1px solid #D8EEB2 ";
runtimeStyle.borderBottom= "1px solid #60A239 ";
runtimeStyle.borderTop= "1px solid #D8EEB2 ";
}
function upit() {
runtimeStyle.borderTop= "1px solid #60A239 ";
runtimeStyle.borderBottom= "1px solid #D8EEB2 ";
runtimeStyle.borderLeft= "1px solid #60A239 ";
runtimeStyle.borderRight= "1px solid #D8EEB2 ";
}
//COPYRIGHT(R) RAIN1977
</SCRIPT>
</PUBLIC:COMPONENT>
------解决方案-------------------- <style type= "text/css " media= "all " title= "Default ">
.mycss {
color:red;
wuxinlangman:expression(onmousemove=function(){
this.style.color= "blue ";
},onmouseout=function(){
this.style.color= "red ";
})
}
</style>
<body id= "wuxinlangman ">
<input class= "mycss " value= "wuxinlangman "/>
</BODY>
</HTML>
这样也可以!
不过推荐使用htc
------解决方案--------------------直接应用就可以...
------解决方案--------------------竟然可以这样写,收藏
------解决方案--------------------JF
------解决方案--------------------长见识了
------解决方案--------------------张见识了,真的
------解决方案--------------------牛。
------解决方案--------------------可以使用.htc文件
但感觉应该通过js控制元素的显示,而不是反其道而行!
------解决方案--------------------mark一个
------解决方案--------------------mark
------解决方案--------------------mark