Jquery 并触发对隐藏按钮的点击

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1091636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:39:05  来源:igfitidea点击:

Jquery and trigger a click on a hidden button

asp.netjquery

提问by RubbleFord

I have a hidden button on a form that I need to click in order to fire an asyncpostback trigger that's attached to an update panel.

我在表单上有一个隐藏按钮,我需要单击该按钮才能触发附加到更新面板的 asyncpostback 触发器。

How is this done?

这是怎么做的?

回答by karim79

$('#myHiddenButton').trigger("click");

Or just

要不就

$('#myHiddenButton').click();

See Events/Trigger

请参阅事件/触发器

回答by Anh Hoang

If you set the Visible property to false; typically in .net the control will not be rendered in the HTML output after the page is processed. Therefore as far as jQuery is concerned, the button does not exist.

如果您将 Visible 属性设置为 false;通常在 .net 中,处理页面后,控件不会在 HTML 输出中呈现。因此,就 jQuery 而言,该按钮不存在。

You can do a View Source on the page to verify this.

您可以在页面上执行查看源代码来验证这一点。

If you want to do this, instead of using the Visible property, you can do something like:

如果要执行此操作,可以不使用 Visible 属性,而是执行以下操作:

<asp:Button ID="HiddenButtonID" runat="server" style="visibility: hidden; display: none;" />

Then you can using jQuery to click button as :

然后您可以使用 jQuery 单击按钮为:

$("#HiddenButtonID").click(); //Remember that in button, you must set ClientIDMode = "static"

or

或者

$("#<%=HiddenButtonID.ClientID%>").Click();

回答by Philippe Leybaert

How about

怎么样

$("#buttonid").click();