如何.on适用于$(文件)

4us*_*ons 5 javascript jquery

我是那个新手,所以我很抱歉要求困惑和简单的想法:-)

我的JS代码不适用于具有从ajax-call和php端加载的表单的moadal.

我想我必须像这样调用函数

$(document).on('click', '#tags', function ()
Run Code Online (Sandbox Code Playgroud)

我现在不知道如何将原始代码更改为此 - 也许有人可以帮助我并为我解释一下?

$('#tags').on({  click: function(e) {
	e.preventDefault();
	alert('geklickt');},
	mouseenter: function(e) {
		alert('mouse enter!');
	}
});
Run Code Online (Sandbox Code Playgroud)

如果我只使用"$('#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();
    });
});
Run Code Online (Sandbox Code Playgroud)

我必须改变哪些部分"document.on"支持是可以想象的?

A. *_*lff 2

只需传递字符串选择器

$(document).on({
  click: function(e) {
    e.preventDefault();
    alert('geklickt');
  },
  mouseenter: function(e) {
    alert('mouse enter!');
  }
}, '#tags');
Run Code Online (Sandbox Code Playgroud)