我有index.php,将通过单击按钮将index-edit.php加载到的index.php中<div class="edit-wrapper"> </div>
。我在index.php中有一些输入,在index-edit.php中有一些输入。我想.active
重点关注添加类,但是jQuery并未将.active
index-edit.php中的类添加到其中,但其余部分(不是index-edit.php)工作正常。
看我的script.js。
$( input ).focusout( function() {
$( this ).addClass('active');
});
$( document ).on( "click", ".btn", function() {
$('.edit-wrapper').load('index-edit.php');
});
由于输入是动态添加的,因此您需要event delegation
用于注册事件处理程序
// New way (jQuery 1.7+) - .on(events, selector, handler)
$(document).on('focusout', 'input', function(event) {
$(this).addClass('active');
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句