gpt4 book ai didi

JQuery jquery-1.7.1.min.js live() 不推荐使用 on()

转载 作者:行者123 更新时间:2023-12-01 02:33:56 25 4
gpt4 key购买 nike

来自 jQuery 网站:

As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.

在 1.7.1 版本中,我尝试将所有 live() 更改为 on(),但没有成功。有谁知道为什么吗?

<小时/>

这就是它的调用方式:

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>

这是不起作用的脚本之一:

$(".toBeSaved [col=ISRC] input").on('change',function() {
var pid = $(this).parent().parent().attr('primary_key');
$("[primary_key="+pid+"] [col=isrc_id] input").val('');
$("[primary_key="+pid+"] [col=isrc_id] input").css({'border':'1px solid red','background-color':'#e8b7cf'});
});

html:

<tr primary_key="44" class="toBeSaved">
<td col="ISRC" style="width: 91px; " class="editableCell"><input class="editableInput auto" type="text" undefined=""></td>
<td col="LineYear" style="width: 35px; " class="editableCell"><input class="editableInput " type="text"></td>
<td col="isrc_id" style="width: 41px; " class="editableCell"><input class="editableInput undefined" type="text" undefined="" readonly="readonly"></td></tr>

我可以问一下 - 为什么是“-1”?我的问题到底哪里出了问题?

最佳答案

将代码从使用 .live 转换为 .on 不仅仅是用 替换对 .live 的调用.on 调用。它们接受不同的参数,并在不同的选择器上调用。例如,旧语法:

$('a').live('click', function () {});

.on:

$(document).on('click', 'a', function () {});

此语法为您提供了更好的控制和灵 active 。

我建议阅读文档: http://api.jquery.com/on/

有关从 .live 转换为 .on 的信息: http://api.jquery.com/live/

关于JQuery jquery-1.7.1.min.js live() 不推荐使用 on(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9805307/

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