码迷,mamicode.com
首页 > 其他好文 > 详细

当页面加载完成时,JQ触发添加页面的元素的事件触发不了。。

时间:2016-10-12 10:52:50      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

有下代码可知:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-1.12.3.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $(#add).click(function () {
               //alert(1);
                var strhtml = "";
                strhtml += "  <input id=‘ab‘type=‘button‘ onclick=‘ab()‘ value=‘onclick‘/>";
                strhtml += "  <input id=‘add‘type=‘button‘ value=‘触发不了add的JQ的click事件‘/>";
                $("#a").append(strhtml);
            })
        });
        function ab(aaa, asa) {
            alert("onclick");
        }
    </script>
</head>
<body>
    <div id="a">
    </div>
    <input id="add" type="button"  value="add" />
</body>
</html>

 

综上,在页面动态添加元素时,触发不了JQ的函数,则我们需要使用JS的绑定事件即可

当页面加载完成时,JQ触发添加页面的元素的事件触发不了。。

标签:

原文地址:http://www.cnblogs.com/May-day/p/5951755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!