Jquery 由于返回错误或停止发布而未提交表格

Jquery 由于返回错误或停止发布而未提交表格,jquery,Jquery,我有一个小弹出窗口,有时包含链接,有时包含表单 我已经对链接进行了设置,但是jQuery正在停止表单提交 我想不出一种方法来允许表单在停止链接的同时提交 jQuery: $('#account').on('click', function() { $('#account-options').fadeIn('slow'); $(document).one('click', function() { $("#account-options").fadeOut('s

我有一个小弹出窗口,有时包含链接,有时包含表单

我已经对链接进行了设置,但是jQuery正在停止表单提交

我想不出一种方法来允许表单在停止链接的同时提交

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; 
}); 

$('#account-options a').on('click', function(e) {
   e.stopPropagation(); 
});
HTML:

{如果注销}
  • {exp:member:login\u form return=“/”}
    • 用户名
    • 密码
    {/exp:member:login\u form}
  • {if:else}
  • {/if}
    这些标记来自表达式引擎


    有人知道如何排序吗?

    您可以检查作为传递事件对象一部分的目标元素:

    $("#account-options").on('click', function(event) { 
        if (event.target.nodeName.toLowerCase() === "a") {
            //anchor, cancel:
            return false; 
        }
    
        //user clicked something else, probably a submit button. Let it go trough.
    });
    

    .

    您可以检查作为传递事件对象一部分的目标元素:

    $("#account-options").on('click', function(event) { 
        if (event.target.nodeName.toLowerCase() === "a") {
            //anchor, cancel:
            return false; 
        }
    
        //user clicked something else, probably a submit button. Let it go trough.
    });
    

    .

    要停止
    li#account
    中所有链接的默认行为,请使用以下命令:

    $('#account').find('a').on('click', function(e) {
        e.preventDefault(); // stops links from being followed
    });
    
    $('#account').find('[href="/login"]').on('click', function() {
        // do the DOM lookup just once and cache it, for better performance
        $('#account-options').fadeIn('slow');
    });
    $(document).on('click', function(e) {
        var target = $(e.target);console.log(target);
        if (target !== $('#account') && target.closest('#account').length < 1) {
            $('#account-options').fadeOut('slow');
        }
    });
    
    然后,要切换帐户选项的淡入(单击
    a[href=“/login”]
    )和淡出(在
    li#account
    之外的任何单击),请使用以下命令:

    $('#account').find('a').on('click', function(e) {
        e.preventDefault(); // stops links from being followed
    });
    
    $('#account').find('[href="/login"]').on('click', function() {
        // do the DOM lookup just once and cache it, for better performance
        $('#account-options').fadeIn('slow');
    });
    $(document).on('click', function(e) {
        var target = $(e.target);console.log(target);
        if (target !== $('#account') && target.closest('#account').length < 1) {
            $('#account-options').fadeOut('slow');
        }
    });
    
    $('#帐户')。查找('[href=“/login”]”)。在('click',function()上{
    //只执行一次DOM查找并缓存它,以获得更好的性能
    $(“#帐户选项”).fadeIn('slow');
    });
    $(文档)。在('单击')上,函数(e){
    var target=$(e.target);console.log(target);
    if(target!=$('#account')&&target.closest('#account')。长度<1){
    $(“#帐户选项”).fadeOut('slow');
    }
    });
    

    不要使用问题中的第二个函数,因为在
    li#account options
    中的任何单击都会返回false,这是阻止提交表单的原因。

    要停止
    li#account
    中所有链接的默认行为,请使用以下命令:

    $('#account').find('a').on('click', function(e) {
        e.preventDefault(); // stops links from being followed
    });
    
    $('#account').find('[href="/login"]').on('click', function() {
        // do the DOM lookup just once and cache it, for better performance
        $('#account-options').fadeIn('slow');
    });
    $(document).on('click', function(e) {
        var target = $(e.target);console.log(target);
        if (target !== $('#account') && target.closest('#account').length < 1) {
            $('#account-options').fadeOut('slow');
        }
    });
    
    然后,要切换帐户选项的淡入(单击
    a[href=“/login”]
    )和淡出(在
    li#account
    之外的任何单击),请使用以下命令:

    $('#account').find('a').on('click', function(e) {
        e.preventDefault(); // stops links from being followed
    });
    
    $('#account').find('[href="/login"]').on('click', function() {
        // do the DOM lookup just once and cache it, for better performance
        $('#account-options').fadeIn('slow');
    });
    $(document).on('click', function(e) {
        var target = $(e.target);console.log(target);
        if (target !== $('#account') && target.closest('#account').length < 1) {
            $('#account-options').fadeOut('slow');
        }
    });
    
    $('#帐户')。查找('[href=“/login”]”)。在('click',function()上{
    //只执行一次DOM查找并缓存它,以获得更好的性能
    $(“#帐户选项”).fadeIn('slow');
    });
    $(文档)。在('单击')上,函数(e){
    var target=$(e.target);console.log(target);
    if(target!=$('#account')&&target.closest('#account')。长度<1){
    $(“#帐户选项”).fadeOut('slow');
    }
    });
    

    不要使用问题中的第二个函数,因为在
    li#account options
    中的任何单击都会返回false,这是阻止您提交表单的原因。

    不清楚您在问什么。您想在点击每一个
    a
    或只点击某个特定的
    a
    时提交表单吗?啊,我很抱歉。当用户单击输入提交按钮时,我需要提交表单。
    {exp:member:login\u form return=“/”}
    是否在html标记中创建表单?如果没有,你就没有要提交的表格。是的,有。所有的HTML都是正确的。如果我删除jQuery,它会提交,但是如果在ul中出现任何点击,你都会返回false,并且不清楚你在问什么。您想在点击每一个
    a
    或只点击某个特定的
    a
    时提交表单吗?啊,我很抱歉。当用户单击输入提交按钮时,我需要提交表单。
    {exp:member:login\u form return=“/”}
    是否在html标记中创建表单?如果没有,你就没有要提交的表格。是的,有。所有的HTML都是正确的。如果我删除jQuery,它会提交,但是如果在ul中点击,就会返回false