2011-05-06 4 views
0

요즘 내가 읽고 내 문제에 대한 자세한 내용은 코드가 여기에 있습니다 :!자바 스크립트 + 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 자식 DIV에서의 버튼 fired.When을 + 얻을 수있는 방법이다 이 버튼은 사람이 ThiefMaster가 지적한 바와 같이, 'parent.childNodes[count]'parent.childNodes[count]을해야

<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> 
+3

'경고 ('parent.childNodes [카운트]) '이어야한다'경고 (parent.childNodes [카운트]); ' – ThiefMaster

답변

2

ME 내 자바 스크립트 코드를 해결하는 데 도움이 될 수 있습니다! 아이 DIV에 자식 된 div 만들어졌습니다. 그런 다음 ID를 얻기 위해, 그냥 .id이고 이름이 적어도 .name

if(parent.childNodes[count].tagName =='DIV') { 
     alert (parent.childNodes[count].id); 
     alert (parent.childNodes[count].name); 
    } 
0

, 당신은 당신의 onclick에 메소드 이름을 추가해야합니다 jQuery를 사용하여 다음

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

, 당신은 w/후 경보를 통해 특정 유형의 구성 요소 및 루프의 배열을 잡을 수

function getoptionvalues() { 
    var dropdownMenus = $("select"); 
    dropdownMens.each(function() { 
     var id = $(this).id; 
     alert(id); 
    }); 
} 
+0

유비쿼터스 인 jQuery는 문제의 일부가 아니 었습니다. 또한'onclick = "getoptionvalues ​​()"'는 잘 작동합니다. 왜 그가'$ :'이 필요하다고합니까? – Jeff

+0

아마 맞을 것입니다. 나는 너무 많은 MVC를 최근에 썼는데, 나는 $ :가이 경우 필요하다고 생각한다. – WEFX

+0

안녕하세요 다시 고마워 대답을 많이하지만 버튼을 누르면 아무 일 없을거야! jquery 코드를 볼 수 있습니까? 내 코드에 대한 자세한 내용을 원한다면 말해줘! 내가 항상 읽고 포럼에 찾고 있지만 솔루션 없음 ! – tasox