0

最近、私は自分の問題について読んで学びました!コードはここにあります:

<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を取得する方法です。このボタンが起動されたときに子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> 
4

2 に答える 2

2

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-06T13:32:07.157 に答える
0

少なくとも、onClick にメソッド名を追加する必要があります。

<input type="button" id="moreFields" value="+" onclick="$:getoptionvalues()"/>

次に、jquery を使用して、特定のタイプのコンポーネントの配列を取得し、アラートを使用してループすることができます。

function getoptionvalues() {
    var dropdownMenus = $("select");
    dropdownMens.each(function () {
        var id = $(this).id;
        alert(id);
    });
}
于 2011-05-06T13:37:31.300 に答える