一般的作法是:
<a href="link1.htm" onfocus="this.blur()">link1</a>
<a href="link2.htm" onfocus="this.blur()">link2</a>
<a href="link3.htm" onfocus="this.blur()">link3</a>
粗看或许还体现不出采用expression的优点,但若是你的页面上有几十甚至上百个连接,这时的你难道还会机械式地Ctrl+C,Ctrl+V么,况且二者一比较,哪一个产生的冗余代码更多呢? css
采用expression的作法以下:
<a href="link1.htm">link1</a>
<a href="link2.htm">link2</a>
<a href="link3.htm">link3</a>
说明:里面的star就是本身任意定义的属性,你能够随本身喜爱另外定义,接着包含在expression()里的语句就是JS脚本,在自定义属性与expression之间可别忘了还有一个引号,由于实质仍是CSS,因此放在style标签内,而非script内。OK,这样就很容易地用一句话实现了页面中的连接虚线框的消除。不过你先别得意,若是触发的特效是CSS的属性变化,那么出来的结果会跟你的本意有差异。例如你想随鼠标的移进移出而改变页面中的文本框颜色更改,你可能想固然的会认为应该写
<style type="text/css">
input {star : expression(onmouseover=this.style.backgroundColor="#FF0000";
onmouseout=this.style.backgroundColor="#FFFFFF")}
</style>
<input type="text">
<input type="text">
<input type="text">
可结果倒是出现脚本出错,正确的写法应该把CSS样式的定义写进函数内,以下所示:
<style type="text/css">
input {star : expression(onmouseover=function()
{this.style.backgroundColor="#FF0000"},
onmouseout=function(){this.style.backgroundColor="#FFFFFF"}) }
</style>
<input type="text">
<input type="text">
<input type="text"> express