我想检测输入和选择上的所有更改。
为此我有一个函数:
$('input, select').on("change", function(){
addSelect(); // This function add a select when another select is clicked
// Some others functions ...
});
当我更改第一个选择的值时,函数 addSelect() 起作用,并且在第一个选择下方创建第二个选择。 但是当我单击第二个选择功能 .on("change") 时不起作用。
如果我点击第一个,该功能就会起作用......
你能帮我吗?谢谢你。
最佳答案
您需要使用 .on()
来动态创建元素,如下所示。
<强> API for .on()
//This will delegate change event to the all input and select under document
$(document).on("change",'input, select', function(){
addSelect(); // This function add a select when another select is clicked
// Some others functions ...
});
关于javascript - .change() 在 .append() 之后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26607043/