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

Categories

0 votes
1.1k 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...