0

私は index.php を持っていて、ボタンをクリックして index.php に index-edit.php をロードします<div class="edit-wrapper"> </div>。index.php にいくつかの入力があり、index-edit.php にいくつかの入力があります。フォーカスアウト時にそれらにクラスを追加したいのです.activeが、jQuery は index-edit.php のものにクラスを追加しません.activeが、残りの部分 (index-edit.php ではない) は正常に動作します。

私のscript.jsを見てください。

$( input ).focusout( function() {
    $( this ).addClass('active');
});

$( document ).on( "click", ".btn", function() {
    $('.edit-wrapper').load('index-edit.php');
});
4

3 に答える 3

0

event delegation入力は動的に追加されるため、イベント ハンドラーを登録するために使用する必要があります。

// New way (jQuery 1.7+) - .on(events, selector, handler)
$(document).on('focusout', 'input', function(event) {
    $(this).addClass('active'); 
});
于 2013-10-30T10:32:14.280 に答える
0

script.js をどこにロードしていますか? これを試して :

$(document).ready(function(){
  $( input ).focusout( function() {
      $( this ).addClass('active');
  });

  $( document ).on( "click", ".btn", function() {
      $('.edit-wrapper').load('index-edit.php');
  });

});
于 2013-10-30T10:32:16.593 に答える