jqueryの内のテーブルに包まれ、選択して、フォーム内の各入力フィールドを無効にします

StackOverflow https://stackoverflow.com/questions/2348520

質問

私は、チェックボックスに基づいてフォームを無効にしています...

私はトラブルdisabled属性を追加することを持っています。

ここで私がこれまでに得たものです。 HTMLます:

<table id="shipInfoTable">
  <tr>
   <td>Name:</td>
   <td><input type="text" name="name" /></td>
  </tr>
  ...
</table>

Javascriptのセレクタ/属性操作(jqueryの):

$("#shipInfoTable tbody tr td input").each(function(index, item){
    item.attr("disabled", true);
});

クロムDevのコンソールエラー: Uncaught TypeError: Object #<an HTMLInputElement> has no method 'attr'

私はitem.each()を警告するときの警告[object HTMLInputElement]

正しく入力要素を選択する方法は非常にわかりません。何が間違っているのでしょうか?

役に立ちましたか?

解決

機能を使用すると、jQueryオブジェクトを与えることはありません。それはする必要があります:

$("#shipInfoTable input").each(function(index, item){
    $(item).attr("disabled", true);
});

(私もあなたのセレクタを簡素化することをノート、それはまだ動作します)
あなたは、各項目に何もelesを行っていない場合、これは同様に動作します:

$("#shipInfoTable input").attr("disabled", true);

他のヒント

...

$("#shipInfoTable tbody tr td input").each(function(){
    $(this).attr("disabled", true);
});

問題が.each()関数内の$()の欠如です...

$("#shipInfoTable tbody tr td input").each(function(index, item){
    $(item).attr("disabled", true);
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top