gpt4 book ai didi

javascript - .on 如何为 $(document) 工作

转载 作者:搜寻专家 更新时间:2023-11-01 04:29:48 25 4
gpt4 key购买 nike

我的 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 支持?

最佳答案

只是pass string selector :

$(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com