Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

asp.net - how to call this Jquery function on Button Click event?

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

var doRedirect = function() { location.href='http://www.example.com' };
$("#button1").click(function() {
    $("#label1").show();
    window.setTimeout("$('#label1').fadeOut('slow', doRedirect)", 10000);
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...