【问题标题】:Perform form validation before Submitting - jQuery在提交之前执行表单验证 - jQuery
【发布时间】:2015-03-15 07:29:04
【问题描述】:

使用 jquery 即兴弹出窗口,我制作了一个表单。但问题是我想在提交之前检查用户输入。有可能吗。
在这里,如果用户在第二个屏幕中选择选项,我想根据 其值 调用另一个弹出窗口。有没有可能。

var my_states = {
state0: {
    title: 'Name',
    html:'<label>First <input type="text" name="fname" value=""></label><br />'+
        '<label>Last <input type="text" name="lname" value=""></label><br />',
    buttons: { Next: 1 },
    //focus: "input[name='fname']",
    submit:function(e,v,m,f){ 
        console.log(f);

        e.preventDefault();
        $.prompt.goToState('state1');
    }
},
state1: {
    title: 'Check Here',
    html:'<table><tr><td><strong>Generate ODEC ID </strong></td><td>:</td><td id=\'gen_odec\' class=\'gen_odec\'>   <select name=\'select_odec\' id=\'select_odec\' class=\'select_odec\'>'+<?php echo json_encode($odecpref)?>+'</select></td></tr></table>',
    buttons: { Back: -1, Next: 1 },
    //focus: ":input:first",
    submit:function(e,v,m,f){ 
        console.log(f);

        if(v==1) {$.prompt.close();
                    return false;}
        if(v==-1) $.prompt.goToState('state0');
        e.preventDefault();
    }
},  
 };  
 $.prompt(my_states);

【问题讨论】:

  • 有人可以指导我如何完成此验证!

标签: jquery forms impromptu


【解决方案1】:

在 jQuery 中使用“on”可以解决问题------就像这样。感谢@Roland Bertolom

$(document).on('change', '#select_odec', function(){
if($(this).val() === 'valueOfDesiredOption') {
    $.prompt.goToState('stateYouNeed');
}

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-02
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多