加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何在Button Click事件上调用此Jquery函数?

发布时间:2020-12-15 22:29:11 所属栏目:asp.Net 来源:网络整理
导读:我想在按钮点击事件中在ASP.NET中调用此 jquery函数 var doRedirect = function() { location.href='http://www.example.com' };$("#button1").click(function() { $("#label1").show(); window.setTimeout("$('#label1').fadeOut('slow',doRedirect)",10000
我想在按钮点击事件中在ASP.NET中调用此 jquery函数
var doRedirect = function() { location.href='http://www.example.com' };
$("#button1").click(function() {
    $("#label1").show();
    window.setTimeout("$('#label1').fadeOut('slow',doRedirect)",10000);
});

解决方法

如果您的jQuery是内联的,您可以执行以下操作:
var doRedirect = function() { location.href='http://www.example.com' };
$("#<%=button1.ClientId%>").click(function() {
    $("#<%=label1.ClientId%>").show();
    window.setTimeout("$('#<%=label1.ClientId%>').fadeOut('slow',10000);
});

如果它不是内联的(即在文件中),则需要以不同的方式获取要使用的客户端控件ID,例如将它们包装在带有ID的div中并通过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',10000);
});

请注意,我使用输出HTML元素类型作为jQuery选择器中的后代.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读