简体   繁体   English

禁用DIV中的链接和表单输入

[英]Disable links and form inputs inside a DIV

I'm trying to find out if it is possible to disable completely all interaction - links (text or images), form inputs/buttons - for an entire DIV. 我试图找出是否有可能完全禁用整个DIV的所有交互-链接(文本或图像),表单输入/按钮。

For example you have a registration form divided in 3 steps, but all displayed in the same page. 例如,您有一个分为3个步骤的注册表,但所有表单都显示在同一页面上。 Unless the first step (DIV1) requirements have been fulfilled, the whole DIV2 would be faded (ie 50%) and absolutely no elements contained within this DIV2 would be clickable. 除非满足第一步(DIV1)的要求,否则整个DIV2将会褪色(即50%),并且绝对不可单击该DIV2中包含的任何元素。

I've seen some other questions where it was mentioned only how to disable form elements, but not plain links. 我看到了其他一些问题,其中仅提到了如何禁用表单元素,而没有提及普通链接。 Would it make sense at all to simply overlap the DIV2 with another DIV (with higher z-index and 50% opacity) which would prevent any interaction with the one underneath? 将DIV2与另一个DIV(具有更高的z索引和50%的不透明度)简单重叠是完全有道理的,这样可以防止与下面的DIV进行任何交互?

Thank you! 谢谢!

UPDATE: I tried going down the "overlapping mask div" route, but for some reason my script only works the first time you click on a "disabled" item. 更新:我尝试过“重叠蒙版div”路线,但是由于某种原因,我的脚本仅在您第一次单击“禁用”项目时才起作用。 Here is the code I'm using: 这是我正在使用的代码:

$('.disabled-mask').click(function() {
$(this).remove();
$('.content-box').not(this).each(function(){
    $(this).append('<div class="disabled-mask"></div>');
    $(this.target).animate({opacity:'hide'}, slidespeed);
});

}); });

"disabled-mask" is a div I am placing above each "content-box" that needs to look disabled. “ disabled-mask”是我要放置在每个需要禁用的“内容框”上方的div。 When clicking on a disabled-mask, I am trying to hide that mask, and then append a mask on every other item. 单击禁用的蒙版时,我试图隐藏该蒙版,然后在其他所有项目上附加一个蒙版。 As I said, first time I click on it works fine, but after that nothing happens. 就像我说的那样,我第一次单击它效果很好,但是之后什么也没有发生。

Thanks in advance for your help. 在此先感谢您的帮助。

Setting the disabled attribute on links is non-standard and should be avoided. 在链接上设置disabled属性是非标准的 ,应避免使用。 Creating an overlapping <div> element is probably the best solution. 创建重叠的<div>元素可能是最好的解决方案。

还有两种可能:通过js / jquery将链接标签替换为另一个标签(例如span)或修改链接的点击事件处理程序(仅在客户端启用js时才有效)!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM