简体   繁体   English

jQuery警报没有调用

[英]jQuery alert not calling

HTML HTML

My button 我的按钮

<asp:Button ID="submitbtn" runat="server" Text="Save" OnClientClick="addchild()" CssClass="btn blue" />

Javascript 使用Javascript

and my javascript function 和我的javascript函数

function addchild() {
        alert(1);
        $("#<%= submitbtn.ClientID %>").click(function () {
            alert(2);
            var firstnme = document.getElementById("<%=firstnametxt.ClientID%>");
            alert(firstnme);
            if (firstnme = "") {
                $("#<%=firstnametxt.ClientID%>").css("border", "1px solid red");
            }
        })
  }

and the second alert(2) is not calling and also jQuery click function is not calling please somebody help me to sort out the issue 并且第二个警报(2)没有调用,并且jQuery点击功能也没有调用请有人帮我解决问题

why do you need to use $("#<%= submitbtn.ClientID %>").click(function () {}) again? 为什么你需要使用$("#<%= submitbtn.ClientID %>").click(function () {})再次$("#<%= submitbtn.ClientID %>").click(function () {}) addchild function is firing once and you can use below code addchild函数触发一次,你可以使用下面的代码

function addchild() {
        alert(1);
        alert(2);
        var firstnme = document.getElementById("<%=firstnametxt.ClientID%>");
            alert(firstnme);
            if (firstnme = "") {
                $("#<%=firstnametxt.ClientID%>").css("border", "1px solid red");
            }
    }

try this jquery click function is not calling because you use asp.net button instead of html button 试试这个jquery点击功能没有调用因为你使用asp.net按钮而不是html按钮

Html: HTML:

 <input type="button" id="submitbtn"  value="Save" onclick="addchild()"/>

jquery: jQuery的:

function addchild() {
    alert(1);
         $("#<%= submitbtn.ClientID %>").click(function () {
        alert(2);
        var firstnme = document.getElementById("  <%=firstnametxt.ClientID%>");
        alert(firstnme);
        if (firstnme = "") {
            $("#<%=firstnametxt.ClientID%>").css("border", "1px solid red");
        }
    });      
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM