这些天,我读到了更多关于我的问题的知识!代码在这里:
<div align="right" id="parent" name="parent">
<select name="select30" id="select30" value=""/>here inside i have options values and work dynamically with query to my DB</select>
<input type="button" id="moreFields" value="+" onclick=""/> //add select tags
<input type="button" value="-" onclick="" /> //remove select tags
<div name="child" id="writeclone"></div> //here cloned the child from parent DIV
</div>
<input type="button" name="enter" id="" value="ENTER" onclick="getoptionvalues();"/>我的问题是,当+ button fired.When这个按钮触发create child DIV时,我如何从子DIV中获取名称或id!!有人能帮我改正我的JAVASCRIPT代码吗
<script>
function getoptionvalues() {
var parent=document.getElementById('parent');
for (var count=0;count<parent.childNodes.length;count++) {
if(parent.childNodes[count].tagName =='DIV') {
alert ('parent.childNodes[count]');
}
}
}
</script> 发布于 2011-05-06 21:32:07
正如ThiefMaster指出的,'parent.childNodes[count]'应该是parent.childNodes[count]。然后,为了获得id,它只是.id,名称是.name
if(parent.childNodes[count].tagName =='DIV') {
alert (parent.childNodes[count].id);
alert (parent.childNodes[count].name);
}发布于 2011-05-06 21:37:31
至少,您需要在onClick中添加一个方法名称:
<input type="button" id="moreFields" value="+" onclick="$:getoptionvalues()"/>然后,使用jquery,您可以获取特定类型的组件数组,然后遍历w/ alert:
function getoptionvalues() {
var dropdownMenus = $("select");
dropdownMens.each(function () {
var id = $(this).id;
alert(id);
});
}https://stackoverflow.com/questions/5912111
复制相似问题