第一:
当您使用双引号“在HTML中使用单引号”在其属性。
这
<div id="rating_poll_front" onmouseover="this.css("background-color","red")" onmouseleave="this.css("background-color","yellow");" style="background-color:yellow;"></div>
应该是:
<div id="rating_poll_front" onmouseover="this.css('background-color','red')" onmouseleave="this.css('background-color','yellow');" style="background-color:yellow;"></div>
二:
由于PHP代码也使用单引号内的PHP的单引号之前,所以用一个反斜杠:
例如:
echo '<div id="rating_poll_front" onmouseover="this.css(\'background-color\',\'red\')" onmouseleave="this.css(\'background-color\',\'yellow\');" style="background-color:yellow;"></div>';
第三,在javascript中没有像css()那样的属性,请使用this.style。的backgroundColor:
所以,你的代码最终变为:
echo '<div id="rating_poll_front" onmouseover="this.style.backgroundColor=\'red\';" onmouseleave="this.style.backgroundColor=\'yellow\';" style="background-color:yellow;">Hello</div>';
当谈到浏览器将运行像片段:
<div id="rating_poll_front" onmouseover="this.style.backgroundColor='red';" onmouseleave="this.style.backgroundColor='yellow';" style="background-color:yellow;">Hello</div>
'this'给HTMLElement对象没有'.css()'。改用'$(this)'。 –
,因为'this'不是一个jQuery对象 –