我有一个asp按钮。它是服务器端的,所以我只能向登录的用户显示它,但是我希望它运行javascript函数,并且似乎在runat =“ server”时始终调用回发事件。我还有一个常规按钮(<input...>)不在服务器上运行,并且工作正常...如何使此按钮仅运行javascript而不能回发?
3 回答
catspeake
TA贡献1111条经验 获得超0个赞
完成后让您的JavaScript返回false。
<asp:button runat="server".... OnClientClick="myfunction(); return false;" />
慕运维8079593
TA贡献1876条经验 获得超5个赞
YourButton.Attributes.Add("onclick", "return false");
要么
<asp:button runat="server" ... OnClientClick="return false" />
幕布斯6054654
TA贡献1876条经验 获得超7个赞
您可以使用jquery click操作并使用preventDefault()函数来避免回发
<asp:button ID="btnMyButton" runat="server" Text="MyButton" />
$("#btnMyButton").click(function (e) {
// some actions here
e.preventDefault();
}
添加回答
举报
0/150
提交
取消