开发者

jQuery apply onmouseover event attribute to tr, works in Firefox but in no other browser

I want a certain Javascript function to be called when the user mouse-overs / mouse-outs or clicks on all table rows (tr) with an id beginning with 'pos_'. I want to apply this from Javascript in order to reduce the size of the original HTML sent from the web server.

The following experiment with onmouseover works in Firefox, but in none of Google Chrome, MSIE 8, Safari or Opera:

var x = $('tr[id^=\'row_\']');
alert(x);
$(x).attr('onmouseover', 'alert("aaa");');
$('td:eq(1)',$(x)).addClass('result');

In all 5 browsers the 3 lines except the o开发者_C百科ne with onmouseover works. The line with onmouseover only works in Firefox.

The javascript I was planning on executing instead of the alert, once it works, is something like

myMouseOver(this);

in order to perform some javascript work based on the row data contents when the mouse is hovering over it. (No, the work cannot be done only using CSS).

How do I apply an onmouseover event so it works in several of the relevant browsers?


Have a look at the mouseover function in jQuery, instead of setting the onmouseover attribute. See the API here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜