jquery .on()方法加载事件

我们如何使用jquery .on()方法加载事件例如代码是: –
<a href="#" id="add">Add</a>
<div id="initial">
     <input type="text" class="abc" name="in">
</div>

和它的jquery

jQuery(document).ready(function() {
    var x=$('#initial').html();
    $('#add').click(function(){
        $('body').append(x);
    });
    $(document).on('load','.abc',function(){
        alert('started');
    });
});

解决方法

参见 http://api.jquery.com/on/

它说

In all browsers,the load,scroll,and error events (e.g.,on an <img>
element) do not bubble. In Internet Explorer 8 and lower,the paste
and reset events do not bubble. Such events are not supported for use
with delegation,but they can be used when the event handler is
directly attached to the element generating the event.

如果要添加新的输入框时要做某事,则可以在添加代码之后直接写入代码

$('#add').click(function(){
        $('body').append(x);
        // Your code can be here
    });

如果您想要在文档中的第一个输入框加载时执行相同的代码,那么您可以在两个地方编写一个函数调用它,即$(‘#add’)。点击和文档的就绪事件

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...