Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery如何在执行函数时全局禁用onclick?_Jquery_Html_Ajax - Fatal编程技术网

jquery如何在执行函数时全局禁用onclick?

jquery如何在执行函数时全局禁用onclick?,jquery,html,ajax,Jquery,Html,Ajax,我有一个带有链接的html菜单,通过ajax加载页面的主要内容。菜单中的href链接为空,内容通过onclick绑定函数加载: <a href="#" onclick=home_link()> <i class="icon-home"></i> <span>Home</span> </a> function home_link() { $.ajax({ url: 'home.html

我有一个带有链接的html菜单,通过ajax加载页面的主要内容。菜单中的href链接为空,内容通过onclick绑定函数加载:

<a href="#" onclick=home_link()>
    <i class="icon-home"></i>
    <span>Home</span>
</a>

function home_link() {
    $.ajax({
        url: 'home.html',
        dataType: 'html',
        cache : false,
        success: function(html) {
            $('#content_div').append(html);
        }
    });

函数home_link(){
$.ajax({
url:'home.html',
数据类型:“html”,
cache:false,
成功:函数(html){
$('#content_div').append(html);
}
});
我在菜单中有几个这样的链接,如果我一个接一个地单击它们,它可以正常工作,但是如果我在一个已加载的链接中单击另一个链接,则会发生不需要的事情,例如各种内容进入


我想在函数执行时全局禁用
onclick
,然后重新启用它或类似的功能,以防止在加载链接时单击其他链接。

一个简单的方法是添加一个div覆盖,防止网站中的所有单击。在触发单击时显示它,在他做到了:

#disableDiv{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10001;
}
该div将插入到
标记之前。我今天读到一个IE问题,它允许基础元素触发单击事件。解决方案是添加背景。如果不需要背景,可以添加第二行,否则保留它:

background: #CCC;
opacity: 0; /* 0.5 would be nice with this color too */
使用unbind()…引用