Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.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 如果返回false,如何在提交时关闭引导模式?_Javascript_Php_Jquery_Twitter Bootstrap 3_Jquery Validate - Fatal编程技术网

Javascript 如果返回false,如何在提交时关闭引导模式?

Javascript 如果返回false,如何在提交时关闭引导模式?,javascript,php,jquery,twitter-bootstrap-3,jquery-validate,Javascript,Php,Jquery,Twitter Bootstrap 3,Jquery Validate,大家好,我想问一下,如果返回错误,如何关闭提交时的引导模式?因为当表单返回false时,如果单击“提交”,我的模式将无法关闭 这是我使用Jquery验证的验证: <script> $(function() { // Disable Enter Key on submit $('#myform').keypress(function(event) { if(event.which == 13 || event.keyCo

大家好,我想问一下,如果返回错误,如何关闭提交时的引导模式?因为当表单返回false时,如果单击“提交”,我的模式将无法关闭

这是我使用Jquery验证的验证:

<script>
    $(function() {

        // Disable Enter Key on submit
        $('#myform').keypress(function(event) {
            if(event.which == 13 || event.keyCode == 13) {
                event.preventDefault();
                return false;
            }
        });

        $.validator.addMethod("nameRegex", function(value, element) {
            return this.optional(element) || /^[a-zA-Z\s\.]+$/i.test(value);
        }, "Please input alphabet only");

        $('#myform').validate({
            ignore: "",
            rules: {
                fname : {
                    required: true,
                    nameRegex: true
                },
                lname : {
                    required: true,
                    nameRegex: true
                },
                position : {
                    nameRegex: true
                },
                supervisor_name : {
                    required: true,
                    nameRegex: true
                }
            },
            messages: {
                fname: {
                    required: "This field is required",
                    nameRegex: "Please input alphabet only"
                },
                lname: {
                    required: "This field is required",
                    nameRegex: "Please input alphabet only"
                },
                position: {
                    nameRegex: "Please input alphabet only"
                },
                supervisor_name: {
                    required: "This field is required",
                    nameRegex: "Please input alphabet only"
                }
            },
            errorPlacement: function (label, element) {
                label.insertAfter(element);
            }
        });
    });
</script>

$(函数(){
//在提交时禁用Enter键
$('#myform')。按键(函数(事件){
if(event.which==13 | | event.keyCode==13){
event.preventDefault();
返回false;
}
});
$.validator.addMethod(“nameRegex”,函数(值,元素){
返回此.optional(element)| |/^[a-zA-Z\s\.]+$/i.test(value);
},“请仅输入字母表”);
$(“#myform”)。验证({
忽略:“,
规则:{
fname:{
要求:正确,
nameRegex:对
},
名称:{
要求:正确,
nameRegex:对
},
职位:{
nameRegex:对
},
主管姓名:{
要求:正确,
nameRegex:对
}
},
信息:{
fname:{
必填项:“此字段为必填项”,
nameRegex:“请仅输入字母表”
},
名称:{
必填项:“此字段为必填项”,
nameRegex:“请仅输入字母表”
},
职位:{
nameRegex:“请仅输入字母表”
},
主管姓名:{
必填项:“此字段为必填项”,
nameRegex:“请仅输入字母表”
}
},
errorPlacement:函数(标签、元素){
标签。插入符(元素);
}
});
});
这是我的表格

<form id="myform" role="form" style="width: 800px;" action="change_info.php" method="POST">
                    <div class="red">
                        <div><label for="atasan"><b>First Name</b></label>  </div>
                    </div>              
                    <input class="col-md-4 col-xs-4 form-control3" id="fname" type="text" name="fname" value="<?php echo $get_data['first_name'] ?>" autocomplete="off"><br>
                    <br>
                    <div class="red">
                        <div>
                            <label for="atasan"><b>Last Name</b></label>    
                        </div>
                    </div>              
                    <input class="col-md-4 col-xs-4 form-control3" id="lname" type="text" name="lname" value="<?php echo $get_data['last_name'] ?>" autocomplete="off"><br>
                    <br>
                    <div>
                        <label for="atasan"><b>Position</b></label> 
                    </div>              
                    <input class="col-md-4 col-xs-4 form-control3" id="atasan" type="text" name="position" value="<?php echo $get_data['position'] ?>" autocomplete="off"><br>
                    <br>
                    <div class="red">
                        <div>
                            <label for="atasan"><b>Supervisor Name</b></label>
                        </div>
                    </div>                  
                    <input class="col-md-4 col-xs-4 form-control3" id="atasan" type="text" name="supervisor_name" value="<?php echo $get_data['supervisor_name'] ?>" autocomplete="off"><br>
                    <br>
                    <button class="btn btn-primary" type="button" data-target="#myModal" data-toggle="modal">OK</button>

                    <!-- Modal START -->
                        <div class="modal fade" id="myModal" role="dialog">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                                        <h3><b>Change Name</b></h3>
                                    </div>
                                    <div class="modal-body" style="float: center;">
                                        <h3 style="text-align: center;" class="modal-title"><b>Are you sure?</b></h3>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-thumbs-up"></span> <b>Yes!</b></button>
                                        <button class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-thumbs-down"></span><b>No!</b></button>
                                    </div>
                                </div>
                            </div>                          
                        </div>
                        <!-- Modal END -->

                </form>

名字

“#myModal将是您打开并想要关闭的引导模式的domElementId

谢谢我刚刚意识到使用$(#myModal')。modal('hide');在我的jQuery上。谢谢,如果这个答案是正确的,请将它设置为正确答案
// If the modal is showing toggle will hide it
$('#myModal').modal('toggle');
// If you want to make sure it hides even if not showing.
$('#myModal').modal('hide');