0

動的に作成されたandを含む1 つのDIV要素があります。TEXTAREAs<input type="file"/><input type="checkbox"/>

DIV現在、以下のように上記の3つのイベントをバインドしています

jQuery("#uniqueId ").bind("click change keypress", function(e){
    ....
    ....
});

入力ボタンをクリックしfileてファイルを参照してアップロードするか、チェックボックスをオンにすると、次のエラーが表示されます。

Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable. 

myxFunction myXjavscript.js:1172
(anonymous function) myXjavscript.js:109
f.event.dispatch jquery-1.7.1.min.js:3
h.handle.i

そのため、file入力checkboxが機能せず、エラーがスローされます。TEXTAREA上記のイベントのみをa の下の他の要素ではなくバインドしたいだけですDIV

イベントを一緒に使用する"click change keypress"理由は、Chrome で Textarea に対して動的操作を実行して、Textarea からテキストを追加/編集/削除した後にカーソル位置を取得しているためです。これらすべてを記録するには、これら 3 つのイベントを追加する必要がありました。

どうすればこれを達成できますか?

4

2 に答える 2

1

If you only want to bind the events to the textareas contained within #uniqueId, use the second argument (delegate selector):

jQuery("#uniqueId ").on("click change keypress", "textarea", function(e){
    ....
    ....
});

Edit: didn't realize you were using .bind, always use .on! It's awesome. http://api.jquery.com/on/

于 2013-09-30T07:32:52.123 に答える
0

You should check the element before using it like,

if(jQuery("textarea#uniqueId").length)
{
  jQuery("textarea#uniqueId").bind("click change keypress", function(e){
      ....
      ....
  });
}

Or if the element is exists in page then write your code in document ready function like,

$(function(){
  jQuery("textarea#uniqueId").bind("click change keypress", function(e){
      ....
      ....
  });
});

Also id must be unique if you id conflicts with other elements the you should specify element with id like textarea#uniqueid

于 2013-09-30T07:29:53.060 に答える