gpt4 book ai didi

javascript - 在 html 中作为 id 传递的 jQuery 值

转载 作者:可可西里 更新时间:2023-11-01 13:26:39 25 4
gpt4 key购买 nike

可以将 jQuery 变量作为 Id 在 Html 中传递。例如

 $(document).on('click', '.addvideo', function () {
var dynamicID = $(this).attr('id');
});

这里我得到了当前点击的 id 值“dynamicID”。我想将这个值传递给另一个变量,如下所示

$('#'+dynamicID).change(function(){
alert('hi');
});

我试过像上面那样。但我收到错误消息“ReferenceError: dynamicID is not defined”。如何解决这个问题?

最佳答案

在addvideo点击事件里面写change事件,那么只有它会绑定(bind):

$(document).on('click', '.addvideo', function () {
var dynamicID = $(this).attr('id');
$('#'+dynamicID).change(function(){
alert('hi');
});
});

关于javascript - 在 html 中作为 id 传递的 jQuery 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37073745/

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