Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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

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 仅在父级上返回false_Jquery_Html - Fatal编程技术网

Jquery 仅在父级上返回false

Jquery 仅在父级上返回false,jquery,html,Jquery,Html,我正在使用return false停止父链接触发。父链接用于打开下拉列表 我的问题是,这个return false也为下拉列表中的孩子设置了return false 我怎样才能只将父链接设置为false,而将所有子链接设置为true jQuery: $('#account').on('click', function() { $('#account-options').fadeIn('slow'); $(document).one('click', function() {

我正在使用return false停止父链接触发。父链接用于打开下拉列表

我的问题是,这个return false也为下拉列表中的孩子设置了return false

我怎样才能只将父链接设置为false,而将所有子链接设置为true

jQuery:

$('#account').on('click', function() {
    $('#account-options').fadeIn('slow'); 
    $(document).one('click', function() { 
        $("#account-options").fadeOut('slow'); 
    });
    return false;
});

$("#account-options").on('click', function() { 
    return false; 
});
HTML:

  • 谢谢。

    试试这个:

    $("#account-options>li").on('click', function() { 
        return true; 
    });
    

    您好,

    您遇到了事件传播。当您单击其中一个

    $("#account-options>li").on('click', function() { 
        return true; 
    });
    
    $('#account-options a').on('click', function(e) {
       e.stopPropagation(); 
    });