2012-04-15 13 views
0

jQueryが名前を配列のサブフィールドとするときに、オブジェクトを選択する適切な方法は何ですか?配列のサブフィールドのjQueryセレクター?

私はspontanouslyみました:

$('select[name=field[subfield]]').change(function(){ 
    alert('houston we have contact'); 
}); 

DOMオブジェクトがある:引用符を追加

<select name="field[subfield]"> 
    <option>..</option> 
    <option>..</option> 
    <option>..</option> 
</select> 

答えて

3

試してみてください。

$('select[name="field[subfield]"]').change(function(){ 
    alert('houston we have contact'); 
}); 

の作業のデモ:http://jsfiddle.net/hHHMS/

0

eZakによると、答える。同じ引用符を使用する場合はバックスラッシュ。

シングルqoutes:

$('select[name=\'field[subfield]\']').change(function(){ 
    alert('houston we have contact'); 
    }); 

二重引用符:

$("select[name=\"field[subfield]\"]").change(function(){ 
    alert('houston we have contact'); 
    }); 

二重引用符と単一引用符:

$("select[name='field[subfield]']").change(function(){ 
    alert('houston we have contact'); 
    }); 

単一引用符と二重引用符:

$('select[name="field[subfield]"]').change(function(){ 
    alert('houston we have contact'); 
});