gpt4 book ai didi

javascript - jquery 中的动态容器名称

转载 作者:行者123 更新时间:2023-11-30 12:14:04 25 4
gpt4 key购买 nike

好吧,我有多个按钮,它们使用不同的 ID 调用相同的 javascript 函数。

这是我的功能

function concur(id) {
//alert(id);
//throw ajax request
$.ajax({ //create an ajax request to load_page.php
type: "GET",
url: "ajax_getter.php?requestid=1&r=" + id,
dataType: "html", //expect html to be returned
success: function (response) {
$("#container").html(response);
//alert(response);
}
}); //ajax end
}

如果我必须将 id 作为容器名称,我该怎么办?我的意思是,这个 $("#id").html(response); 是否适用于函数内所有动态变化的 id?这对我不起作用。什么是最佳解决方案?

最佳答案

使用字符串连接在 jQuery 选择器中使用变量。

$("#" + id).html(response); 

关于javascript - jquery 中的动态容器名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32905809/

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