0

我有一个 if 语句,当单击页面上的下一个按钮时,当前会弹出一个警报。我不确定我必须删除什么才能让警报消失。我仍然需要这个按钮来带你到下一页。无论我如何调整,最终结果都是按钮不再起作用。这是代码:

$('.dab_button').click(function(){
if($('[name=select_value1]').val()=='' ||
    $('[name=select_value2]').val()=='' ||
    $('[name=select_value3]').val()==''){
        alert('Please select your gift choices for each or the three levels.');             
    } else{
        <? if($members_info['individual']=='no'):?>
            window.location.href = "/dab/profile";
        <? else:?>
            window.location.href = "/hq/edit_page";
        <? endif;?>         
    }     
});
4

1 回答 1

2

Just comment it out?

$('.dab_button').click(function(){
    if($('[name=select_value1]').val()==""||$('[name=select_value2]').val()==""||$('[name=select_value3]').val()==""){
        ; // do nothing
        // alert('Please select your gift choices for each or the three levels.');             
    } else{
<? if($members_info['individual']=='no'):?>
        window.location.href = "/dab/profile";
<? else:?>
        window.location.href = "/hq/edit_page";
<? endif;?>         
    }     
});

But I stronly recommend to give some feedback to the user when the button does nothing (does not navigate away), because they have not filled out all inputs. If you wanted to navigate in any case, just remove that if-statement (note that you also have serverside processing code, which has nothing to do with the javascript):

$('.dab_button').click(function(){
<? if($members_info['individual']=='no'):?>
    window.location.href = "/dab/profile";
<? else:?>
    window.location.href = "/hq/edit_page";
<? endif;?>
});
于 2012-07-17T20:41:01.460 回答