简体   繁体   中英

change background color of current element

how can I change the background color of current element using plain javascript? for instance

<li onmouseover="this.backgroundColor:#000;">something</li>

This doesn't work, but you will get the idea what I want to do. Thank you

快好了。

<li onmouseover="this.style.backgroundColor='#000';">something</li>
this.style.backgroundColor= 'black';

或者,如果可以的话,最好使用简单的CSS:

li:hover { background-color: black; }

CSS hover would probably be the most elegant solution, there is an IE6 fix for this: csshover.htc

But if it were me I would use jQuery, and it would provide you excellent cross-browser support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM