首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >javascript + div标签

javascript + div标签
EN

Stack Overflow用户
提问于 2011-05-06 21:26:24
回答 2查看 659关注 0票数 0

这些天,我读到了更多关于我的问题的知识!代码在这里:

代码语言:javascript
复制
<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代码吗

代码语言: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> 
EN

回答 2

Stack Overflow用户

发布于 2011-05-06 21:32:07

正如ThiefMaster指出的,'parent.childNodes[count]'应该是parent.childNodes[count]。然后,为了获得id,它只是.id,名称是.name

代码语言:javascript
复制
    if(parent.childNodes[count].tagName =='DIV') {
        alert (parent.childNodes[count].id);
        alert (parent.childNodes[count].name);
    }
票数 2
EN

Stack Overflow用户

发布于 2011-05-06 21:37:31

至少,您需要在onClick中添加一个方法名称:

代码语言:javascript
复制
<input type="button" id="moreFields" value="+" onclick="$:getoptionvalues()"/>

然后,使用jquery,您可以获取特定类型的组件数组,然后遍历w/ alert:

代码语言:javascript
复制
function getoptionvalues() {
    var dropdownMenus = $("select");
    dropdownMens.each(function () {
        var id = $(this).id;
        alert(id);
    });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5912111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档