gpt4 book ai didi

jquery添加onmouseover属性

转载 作者:行者123 更新时间:2023-12-03 22:57:13 25 4
gpt4 key购买 nike

在 jquery 中,如何向元素添加“onmouseover”事件。

例如

<tr id=row bgcolor=white>

变成了

 <tr id=row bgcolor=white onMouseOver="this.bgColor='red'">

最佳答案

您可以使用attr方法:

$('#row').attr("onMouseOver", "this.bgColor='red'")

但是由于您使用的是 jQuery,我建议使用 on 方法:

$('#row').on('mouseover', function() {
$(this).css('background-color', 'red');
});

关于jquery添加onmouseover属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11532842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com