how to call this Jquery function on Button Click event?

前端 未结 1 1602
感动是毒
感动是毒 2020-12-21 22:36

I wanna call this jquery function in ASP.NET on button click event

var doRedirect = function() { location.href=\'http://www.example.com\' };
$(\"#button1\")         


        
相关标签:
1条回答
  • 2020-12-21 22:51

    If your jQuery is inline, you can do the following:

    var doRedirect = function() { location.href='http://www.example.com' };
    $("#<%=button1.ClientId%>").click(function() {
        $("#<%=label1.ClientId%>").show();
        window.setTimeout("$('#<%=label1.ClientId%>').fadeOut('slow', doRedirect)", 10000);
    });
    

    If it isn't inline (i.e. in a file), you will need to get the client control Id's you want to use in a different way, for example wrapping them in a div with an ID and selecting them through the div:

    <div id="myId">
       <asp:Label runat="server" id="label1" />
       <asp:Button runat="server" id="button1" />
    </div>
    
    var doRedirect = function() { location.href='http://www.example.com' };
    $("#myId input").click(function() {
        $("#myId span").show();
        window.setTimeout("$('#myId span').fadeOut('slow', doRedirect)", 10000);
    });
    

    Note that I am using the output HTML element types as the descendant in the jQuery selector.

    0 讨论(0)
提交回复
热议问题