我的 JS 代码不适用于具有从 ajax 调用加载到 php 端的表单的模式。
我想我必须像下面这样调用函数:
$(document).on('click', '#tags', function ()
我应该如何将原始代码改成这样,谁能帮我解释一下吗?
$('#tags').on({ click: function(e) {
e.preventDefault();
alert('geklickt');},
mouseenter: function(e) {
alert('mouse enter!');
}
});
仅使用 $('#tags')
不起作用。
此外,我必须更改此代码:
$(document).ready(function() {
bookIndex = 0;
$('#bookForm')
// Remove button click handler
.on('click', '.removeButton', function() {
var $row = $(this).parents('.form-group'),
index = $row.attr('data-book-index');
// Remove fields
$('#bookForm')
.formValidation('removeField', $row.find('[name="book[' + index + '].title"]'))
.formValidation('removeField', $row.find('[name="book[' + index + '].isbn"]'))
.formValidation('removeField', $row.find('[name="book[' + index + '].price"]'));
// Remove element containing the fields
$row.remove();
});
});
我必须更改哪些部分才能使用 document.on
支持?
最佳答案
$(document).on({
click: function(e) {
e.preventDefault();
alert('geklickt');
},
mouseenter: function(e) {
alert('mouse enter!');
}
}, '#tags');
关于javascript - .on 如何为 $(document) 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39788986/