ダイアログを閉じて、再度開くとイベントが2重で発生してしまう。
$(document).on('keypress', ~ を使った場合に、2重で読み込まれない方法はないでしょうか。
下記のソースでダイアログを作成。
$('#body div').after('<div id="dialog"></div>'); var $dialog= $('#dialog'); $dialog.dialog({ autoOpen: false, modal : true, width : 700, height : 'auto', position: ['30', 'center'], close : function (event) { $(this).dialog("destroy"); $(event.target).remove(); } }).dialog('open'); $.ajax({ type : 'post', url : '', data : data, dataType : 'html' }).done(function (re) { $dialog.empty().html(re); }).fail(function () { }).always(function() { });
ダイアログを開いた時に下記のソースを含めたファイルを読み込む。
動的に作成されたテキストボックスをエンターしたときに、イベントを起こしたいので、
$(document).on('keypress', を使っています。
<input type="text" name="input[name="hoge[]"]" value=""> <script type="text/javascript"> $(function () { $(document).on('keypress', 'input[name="hoge[]"]', function (e) { if (e.which === 13) { // テキストボックスを増やす処理 } }); }); </script>
「$(document).on('click',」がコード中に出てきません。そこまで記載ください。また、プラグイン/ライブラリは取得した場所のURLを質問文に追記ください。(URLにはリンクを張ることができます)
回答1件
あなたの回答
tips
プレビュー