如何使用jquery禁用页面上的所有链接和输入按钮
我正在 django 中工作,并创建了一个具有字段闭合
的类。当用户为特定对象设置此值时,我想禁用 object_view
页面上的所有按钮和链接。
我正在使用以下 jquery
片段,但它不起作用。任何人都可以帮我找到错误
<script type="text/javascript">
$("a").css('cursor','arrow').click(function(){
return false;
});
$("input").attr('disabled','disabled');
</script>
更新:不工作意味着所有链接和输入按钮仍然有效,即被定向到正确的页面。我已将此代码片段包含在我的 部分中。
I am working in django and have created a class which has a field closed
. When the user sets this value for a particular object, then I want to disable all buttons and links on the object_view
page.
I am using the following jquery
snippet, but it is not working. Can anybody help me find the mistake
<script type="text/javascript">
$("a").css('cursor','arrow').click(function(){
return false;
});
$("input").attr('disabled','disabled');
</script>
Update: Not working means that all the links and input buttons are still working, i.e. being directed to the correct page. I have included this code snippet in my <head>
section.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
您需要
$(document).ready(...)
以便在元素存在于页面上之前代码不会运行。Try:
You need the
$(document).ready(...)
so that the code doesn't run until the elements exist on the page.我想你可以用这样的东西关闭所有链接(即锚标记):
这应该适用于按钮和其他输入
I guess you could turn off all links (that is anchor tags) with something like this:
This should work for buttons and other inputs
您需要将整个内容包装在:
或
将输入限制为按钮:
否则,您将禁用所有输入元素。
You need to wrap the whole thing in:
OR
To limit the input to buttons:
Otherwise you disable all input elements.