用過css樣式我們就知道, 可以定義一批對象的class屬性來指定同一個樣式來統一界面. 但如何統一同類型的對象的事件? 比如:界面有無數個 <img src="**.jpg"> 如何實現鼠標經過此圖片, 圖片的src變成是**_over.jpg?
解決方法: 使用css的expression方法,具體實現要看看.css的寫法:
| /*替換圖片CSS*/ #imgScript { /*這里使用對象ID來通配樣式, 也可以定義一個css函數*/ star:expression( onmouseover = function() { /*替換圖片*/ if(this.hover != null){ this.name = this.src; this.src = this.src.replace('.jpg', '_over.jpg'); this.HasChg = 1; } }, onmouseout = function() { /*還原本來的圖片*/ if(this.HasChg != null){ this.src = this.name; this.HasChg = null; } } ) }/*end imgScript*/ |
新聞熱點
疑難解答