jquery 到 运行 具有多个选择器的克隆函数
jquery to run clone function with multiple selectors
$(document).ready(function() {
$(".add_file_group, .clone_email2, .clone_email").click(function() {
$("#clone_file_group").clone().insertAfter("div#clone_file_group:last");
console.log(this);
});
});
在一个部分中将此功能与不同的选择器一起使用,只有一个选择器有效
正如您的 class 姓名 clone_email2, .clone_email
表明这些是动态生成的。所以你需要使用 delegate event handler
试试这个
$(document).on('click', '.add_file_group, .clone_email2, .clone_email', function () {
$("#clone_file_group").clone().insertAfter("div#clone_file_group:last");
});
Description: Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a
specific set of root elements.
$(document).ready(function() {
$(".add_file_group, .clone_email2, .clone_email").click(function() {
$("#clone_file_group").clone().insertAfter("div#clone_file_group:last");
console.log(this);
});
});
在一个部分中将此功能与不同的选择器一起使用,只有一个选择器有效
正如您的 class 姓名 clone_email2, .clone_email
表明这些是动态生成的。所以你需要使用 delegate event handler
试试这个
$(document).on('click', '.add_file_group, .clone_email2, .clone_email', function () {
$("#clone_file_group").clone().insertAfter("div#clone_file_group:last");
});
Description: Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.