我正在开发一个项目,在该项目中,我需要在调用函数时更改某个类的所有选择输入的值。问题是一些选择输入在 dom 首次加载时并不存在,它们是通过 Javascript 动态创建的。
该函数适用于选择页面加载时存在的所有选择输入,但不适用于动态添加到 dom 的任何选择输入。
我理解与 .on 的事件绑定,但在这种特殊情况下,我并不想关闭像单击这样的事件。我想在调用此函数时获取此类的所有元素。
这是我用来创建新的选择元素的代码。
var this_cell = document.getElementById('produce_batch_line_td['+x+']');
var new_select = document.createElement("select");
new_select.name = "produce_batch_line["+x+"]";
new_select.id = "produce_batch_line["+x+"]";
new_select.className = "produce_batch_line["+invoice_number+"]";
this_cell.appendChild(new_select);
var new_option = document.createElement("option");
new_option.text = "test";
new_option.value = "test";
new_select.add(new_option);
这是我用来选择此类的所有选择元素的代码。
function SetDetailValue(invoice_number, obj) {
$(".produce_batch_line\\["+invoice_number+"\\]").each(function() {
this.value = obj.value;
});
}
如何将此类的项目动态添加到 dom 中?
检查此链接。我已经放置了一个已经存在的。当您单击添加按钮时,它也会动态创建。当您单击设置按钮时,它会使用 java 查询找到它们,并将它们放入 for 循环中,逐一更改每个值。
http://cr8code.co/editor.php?workid=1a446530189d751d0b15ce104a286eee http://cr8code.co/editor.php?workid=1a446530189d751d0b15ce104a286eee
这里是DEMO http://cr8code.co/editor.php?workid=1a446530189d751d0b15ce104a286eee
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)