工作整理日志

JS动态添加元素后事件不起作用失效

解决方案:

$("#table").on("click","td",function(){ alert($(this).attr("id")); });

js给<asp:Label 赋值,以及赋了值而后台却取不到-解决方案
html:
<asp:Label ID="lbl_Test" runat="server" CssClass="cssTest" Text="测试" ></asp:Label>
1.解决赋值问题。
在前端使用Js给ASP.NET服务器控件<asp:Label 赋值时,因为取不到ID值,所以无法通过ID直接获取到该控件对象,这时只要设置控件属性CssClass=“cssTest” 即可,这样Js就可以直接通过类名找到该对象了。
  visilbe 为false的也获取不到

    $("#btnaddbaby").click(function () {
        var monitorid = $(this).attr("id");
        console.log($(this).attr("id"));
 
    });

ddl 动态添加options

  var htmlInfo = "";
                            //ddlbaby
                            $.each(obj, function (n, value) {
                                htmlInfo += " <option value=" + value.BabyKey + ">" + value.BabyName + "/" + value.MotherName + "/" + value.RoomName + "</option>";
                            });
                            $("#ddlbaby").append(htmlInfo);


$(function () {
    //获得绑定数据
    $.ajax({
        type: "POST",
        url: "/ajax/BabyHandler.ashx",
        dataType: "json",
        data: {
            act: 'getlist'
        },
     

 success: function (e) {
            if (e.ResultCode == 1) {
                var obj = e.lstBaby;
                var htmlInfo = "";
                htmlInfo += `<div class=\"babycount\">共有${obj.length}个宝宝 </div>`;
                htmlInfo += `    <div class="contentwrap">`;
                $.each(obj, function (n, value) {

                    htmlInfo += `      <div class="monitor_box">`;
                    htmlInfo += `         <div class="monitorroominfo" style=""><span class="monitornameandroom">房间:${value.RoomName},妈妈:${value.MotherName}</span><a href="#" id=${value.BabyKey}  οnclick='deletbaby(${value.BabyKey})' >删</a></div>`;
                    htmlInfo += `          <div class="monitorbabyinfo"><span class="monitorbabyname">${value.BabyName}</span><span class="monitorbabyid">(ID${value.BabyKey})</span></div>`;
                    htmlInfo += `       </div>`;

                });
                htmlInfo += `      <div class="monitor_box " style=" width: 80px; padding-left: 10px; padding-right: 10px; ">`;
                htmlInfo += `      <div id ="btnaddbaby" class="btnaddbaby" οnclick='addbaby()'> </div>`;
                htmlInfo += `     </div>`;
                htmlInfo += `   </div > `;
                $("#babycontent").html(htmlInfo);
            } else {
                alert(e.ResultMessage);
            }

    });


 

    $("#btnaddbaby").click(function () {
        var monitorid = $(this).attr("id");
        console.log($(this).attr("id"));
        $(".showpop").show();
        $(".bindbaby").hide();
        $(".showbindbabywrap").hide();
        $(".addbabywrap").show();
    });
    $("._monitorempty").click(function () {
        var monitorid = $(this).attr("id");
        console.log($(this).attr("id"));
        $(".showpop").show();
        $(".bindbaby").show(); $(".addbabywrap").hide();
        $(".showbindbabywrap").hide();
        $(".showpop_manitor_name").text(monitorid);
    });

    $("._monitorbaby").click(function () {
        var monitorid = $(this).attr("id");
        console.log($(this).attr("id"));
        $(".showpop").show();
        $(".bindbaby").hide(); $(".addbabywrap").hide();
        $(".showbindbabywrap").show();
        $(".showpop_manitor_name").text(monitorid);
    });


    $(".close").click(function () { $(".showpop").hide(); });

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值