問題は、セレクタの正確なターゲットに関連しているようでした。 元セレクタ"input[name='personsroom[]']"
は動作しますが、input
ドロップOPのコメントに応じなかった[]
文字のエスケープに"[name='personsroom[]']"
ノートを働きました。この特定のケースでは、それがこの"input[name=personsroom[]]"
を使用"[name='personsroom[]']"
►インライン単一引用符を使用したクエリ文字列として問題ではありませんでした、単一引用符で、あなたはこの"input[name=personsroom\\[\\]]"
// The below will fail with "Uncaught SyntaxError..." during execution
//var personroom = document.querySelectorAll("[name=personsroom[]]");
//The below works as we are escaping the special characters
var personroom = document.querySelectorAll("[name=personsroom\\[\\]]");
console.log("1.) personroom.length", personroom.length);
//Also, when using inline quotes, you do not need to escape any characters
var personroom = document.querySelectorAll("[name='personsroom[]']");
console.log("2.) personroom.length", personroom.length);
<input type='textbox' name='personsroom[]' />
<input type='textbox' name='personsroom[]' />
<input type='textbox' name='personsroom[]' />
<input type='textbox' name='personsroom[]' />
よう
[]
をエスケープする必要があります
HTMLを表示してください。 "選択ボックス"を取得しようとすると、なぜ 'querySelectorAll'の呼び出しで' input'を使用していますか? –
http://stackoverflow.com/questions/13987979/how-to-properly-escape-attribute-values-in-css-js-attribute-selector-attr-valueの重複 –