锚链接禁用
I have an anchor link like:<a id="linkOwner" runat="server"></a>
In my codebehind I am disabling it based on some condittions like:linkOwner.Disabled = true; But still the link is click-able.How to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 ASP LinkButton 控件,我认为您可以在服务器端禁用它,它会在客户端正确禁用它。但对此并不积极。另一种方法是使用 javascript。过去,我使用 jQuery 将单击事件添加到禁用的锚点,并返回 false 的空事件。类似于:
return false 让 jQuery 知道不要冒泡事件。
If you use an ASP LinkButton control I think you can just disable it on the server side and it'll properly disable it on the client. Not positive on that though. Another method is to use javascript. In the past I have used jQuery to add a click event to the disabled anchor with a empty event that returns false. Something like:
The return false lets jQuery know not to bubble up the event.
有两种解决方案:
将锚标记更改为
,然后您可以根据需要设置Enabled
属性。您需要向控件添加一个属性,如下所示
There are two solutions:
Change the anchor tag to an
<asp:HyperLink>
then you can set theEnabled
property as you see fit.You need to add an attribute to the control as in
通过调用 javascript void 函数和
调用
另一个将处理您的情况的doAction
函数来禁用锚定按钮。HTML 实现:
一些文本
Javascript实现:
Disable anchor button by calling javascript void function and
call
anotherdoAction
function which will hanle your condition.HTML implementation:
<a href='javascript:void(0);' onclick="doAction()">some text</a>
Javascript implementation: