的javascript + div标签
问题描述:
这些天我已阅读并了解更多关于我的问题的代码是在这里:的javascript + div标签
<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();"/>
我的问题是我怎么能得到的名称或ID +按钮fired.When当从孩子DIV的此按钮激发儿童DIV创建子的DIV!有人可以帮我改正我的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>
答
由于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);
}
答
最起码,你需要一个方法的名称添加到您的onClick:
<input type="button" id="moreFields" value="+" onclick="$:getoptionvalues()"/>
然后,使用jQuery,你可以抓住某种类型的组件,然后循环的阵列至w /警报:
function getoptionvalues() {
var dropdownMenus = $("select");
dropdownMens.each(function() {
var id = $(this).id;
alert(id);
});
}
'警报( 'parent.childNodes [COUNT]');'应'警报(parent.childNodes [COUNT] );' – ThiefMaster 2011-05-06 13:28:07