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();"/>
我的问题是当 + 按钮触发时如何从子 DIV 中获取名称或 id。当此按钮触发时在 Child 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>
these days i read and learn more about my problem!the code is here:
<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();"/>
My problem is how i can get the names or id's from child DIV when + button fired.When this button fired create child DIVs in Child DIV!!Can anybody HELP ME to correct my JAVASCRIPT code
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 ThiefMaster 指出的那样,
'parent.childNodes[count]'
应该是parent.childNodes[count]
。然后要获取id,它只是.id
,名称是.name
As ThiefMaster pointed out,
'parent.childNodes[count]'
should beparent.childNodes[count]
. Then to get the id, it is just.id
and name is.name
至少,您需要向 onClick 添加一个方法名称:
然后,使用 jquery,您可以获取某种类型的组件数组,然后通过警报进行循环:
At the very least, you need to add a method name to your onClick:
Then, using jquery, you can grab an array of components of a certain type, and then loop through w/ alerts: