如何调用按钮单击事件这个jQuery功能? [英] how to call this Jquery function on Button Click event?
本文介绍了如何调用按钮单击事件这个jQuery功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想呼吁在ASP.NET的按钮单击事件这个jQuery功能
VAR doRedirect =功能(){location.href =HTTP://www.example.com中'};
$(#Button1的)。点击(函数(){
$(#LABEL1)显示()。
window.setTimeout(。$('#LABEL1')淡出('慢',doRedirect),10000);
});
解决方案
如果您的jQuery是inline,可以做到以下几点:
VAR doRedirect =功能(){location.href =HTTP://www.example.com中'};
$(#<%= button1.ClientId%GT;)。点击(函数(){
$(#<%= label1.ClientId%GT;)。展();
window.setTimeout($('#<%= label1.ClientId%GT;')淡出('慢',doRedirect),10000);
});
如果它不是内联(即在文件中),您将需要得到你想要以不同的方式使用客户端控件的ID的,例如在 DIV $包裹其中C $ C>一个ID,并选择他们通过
DIV
:
< DIV ID =身份识别码>
< ASP:标签=服务器ID =LABEL1/>
< ASP:按钮=服务器ID =Button1的/>
< / DIV>VAR doRedirect =功能(){location.href =HTTP://www.example.com中'};
$(#MYID输入)。点击(函数(){
$(#MYID跨越)显示()。
window.setTimeout($('#MYID跨度')淡出('慢',doRedirect),10000);
});
请注意,我现在用的是输出HTML元素类型作为jQuery选择后代。
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);
});
解决方案
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.
这篇关于如何调用按钮单击事件这个jQuery功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文