jQuery 禁止点击 divs 元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5259191/
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
disable clicking of a divs element
提问by Jason94
I have div that goes in to an edit mode... the div contains buttons, links++. In edit mode i want to disable all of these, and enable them when i exit edit mode.
我有进入编辑模式的 div... div 包含按钮、链接 ++。在编辑模式下,我想禁用所有这些,并在退出编辑模式时启用它们。
Ive tried
我试过了
$("#container").children().disableSelection();
but it does not work :-(
但它不起作用:-(
回答by Furicane
Edit mode enter:
编辑模式输入:
$("#container").children().bind('click', function(){ return false; });
Edit mode exit:
编辑模式退出:
$("#container").children().unbind('click');
回答by Greg
Give all elements that you want to prevent clicking a class of "noclick", then when in edit mode:
给所有要防止单击“noclick”类的元素,然后在编辑模式下:
$(".noclick").click(function(e) {
if(editMode) {
e.preventDefault();
}
});
回答by Hitesh Prajapati
you use below that will help you:
你在下面使用它会帮助你:
$("#container").hide();
$("#container").hide();
and when exit edit mode do: $("#container").show();
当退出编辑模式时: $("#container").show();
回答by csandreas1
css:
css:
.dis{pointer-events:none}
.dis{pointer-events:none}
Jquery:
查询:
$("#container").addClass("dis"); //disables
$("#container").addClass("dis"); //disables
$("#container").removeClass("dis"); //enables
$("#container").removeClass("dis"); //enables