Javascript Jquery在单击动态添加的按钮时不调用函数
我有一个函数和一些代码:Javascript Jquery在单击动态添加的按钮时不调用函数,javascript,jquery,html,Javascript,Jquery,Html,我有一个函数和一些代码: function findMember(str) { // console.log('search: ' + str); $.post("includes/search.php", { search: str, }, function(data, status) { // console.log(data); $('#creatorSearchMai
function findMember(str) {
// console.log('search: ' + str);
$.post("includes/search.php", {
search: str,
}, function(data, status) {
// console.log(data);
$('#creatorSearchMain').html(data);
});
}
$('#creatorSearchInput').keyup(function() {
var target = $('#creatorSearchInput');
findMember(target.val()); //remove and uncomment other if want to wait before request
});
这将从输入中选择文本,并将其与.post一起使用以查询数据库以搜索具有搜索名称的用户。.post返回添加到div的html代码
在返回的html中有一个按钮:
<button class="followButton " type="submit" value="1">Follow</button>
提前谢谢 使用该代码:
$('#creatorSearchMain').on("click", '.followButton', function() {
#code in here
});
正在动态添加您的按钮,请使用添加单击处理程序
$("#creatorSearchMain").on("click",".followButton", function() {
#code in here
});
*此处,$creatorSearchMain上的选择器应该是静态元素。如果您还解释了其他读者为什么要使用该代码,您的答案将对他们更有帮助。
$("#creatorSearchMain").on("click",".followButton", function() {
#code in here
});