zoukankan      html  css  js  c++  java
  • 当页面加载完成时,JQ触发添加页面的元素的事件触发不了。。

    有下代码可知:

    <%@ 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的绑定事件即可

  • 相关阅读:
    python 基于gevent协程实现socket并发
    python asyncio
    python 池 协程
    python
    python 守护进程
    python 线程 threading模块
    python 安装Django失败处理
    python 队列
    python 锁
    继承,抽象类,多态,封装
  • 原文地址:https://www.cnblogs.com/May-day/p/5951755.html
Copyright © 2011-2022 走看看