Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.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
如何使用javascript或jquery在页面中查找单击事件_Javascript_Jquery - Fatal编程技术网

如何使用javascript或jquery在页面中查找单击事件

如何使用javascript或jquery在页面中查找单击事件,javascript,jquery,Javascript,Jquery,我正在使用这个确认插件 如果我点击主页图标,它会显示确认信息。但是,我只想在我的页面上发生任何键控和单击事件时显示此消息 这是我的密码: $( "body" ).click(function(event) { $('#home').confirmOn('click', function(e, confirmed){ if(confirmed) { window.location='index.html'} else { //If we need to,

我正在使用这个确认插件

如果我点击主页图标,它会显示确认信息。但是,我只想在我的页面上发生任何键控和单击事件时显示此消息

这是我的密码:

$( "body" ).click(function(event) { 
    $('#home').confirmOn('click', function(e, confirmed){
    if(confirmed) { window.location='index.html'}
    else {
        //If we need to, we can do some actions here if the user cancelled the confirmation
    }
})
});

当我直接点击主页而不点击我的页面时,我上面的代码就起作用了。而且,当我点击页面中的任何字段时,它会显示消息,但如果我点击确认框中的“是”或“否”按钮,它将无法导航/工作

试试这个:

$(document).confirmOn('click', function(event) { 
$('#home').confirmOn('click', function(e, confirmed){
    if(confirmed) { window.location='index.html'}
    else {
        //If we need to, we can do some actions here if the user cancelled the confirmation
    }
});
});

对于点击页面,请尝试
$(文档).confirmOn('click',function(e,confirmed){
而不是
$('#home').confirmOn('click',function(e,confirmed){
我使用了您的代码。但是,当我打开页面本身时,它会显示确认框。这段代码中没有错误,请发布您的html代码以便我们可以猜测..1