2014-04-09 4 views
1

에서 명명 된 요소를 선택 :나는 다음과 같은 jQuery를 실행하고 입력 배열

<input type="text" value="hello" name="multy['helloworld']" /> 
<script type="text/javascript"> 
    $(document).ready(function(){ 
    var hello = 'helloworld'; 
    alert($('input[name="multy['+hello+']"]').val()); 
    }) 
</script> 

당신이 명명 된 배열의 키 요소를 선택할 수 없습니다 보 겠지만. 이 문제가 해결 되었습니까?

ta.

안토니

답변

1

예, 요소의 이름에서 작은 따옴표 제거 :

<input type="text" value="hello" name="multy[helloworld]" /> 

그들은 절대적으로이 필요하지됩니다.

+0

고맙습니다. 나는 명성이 없지만 답으로 표시 할 것입니다. – Ukuser32

+0

@ Ukuser32 환영합니다! – VisioN

+0

내 다른 코드에서는이 작업을 수행 할 수 없지만 select [name = "timeSlots [ '+ name +']"] – Ukuser32

0

jquery로 보낼 때 괄호에 두 번 이스케이프 처리해야 jquery도 이스케이프 처리를 알 수 있습니다. 또한 예제의 입력에서 작은 따옴표를 제거했음을 유의하십시오.

<input type="text" value="hello" name="multy[helloworld]" /> 
<script type="text/javascript"> 
    alert($('input[name=multy\\[helloworld\\]]').val()); 
</script> 
관련 문제