亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

引導驗證器在我的代碼中不起作用(沒有拋出錯誤),但在JSFiddle上工作

引導驗證器在我的代碼中不起作用(沒有拋出錯誤),但在JSFiddle上工作

阿晨1998 2022-08-04 17:02:32
當我嘗試在我的和點擊按鈕內使用相同的代碼時,它不起作用。代碼如下:index.htmlRequest Data<!DOCTYPE html><html><head><meta content="text/html;charset=utf-8" http-equiv="Content-Type"><meta content="utf-8" http-equiv="encoding"><link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"><link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/css/bootstrapvalidator.min.css" rel="stylesheet"><script src="https://code.jquery.com/jquery-3.4.0.min.js"></script><script src='http://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/js/bootstrapvalidator.min.js'></script><script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script><script type="text/javascript">        //BEGIN FORM Validations        $('#validateForm').bootstrapValidator({            feedbackIcons: {                valid: 'glyphicon glyphicon-ok',                invalid: 'glyphicon glyphicon-remove',                validating: 'glyphicon glyphicon-refresh'            },            fields: {                patientSets: {                    validators: {                        notEmpty: {                            message: 'Please select a patient set'                        }                    }                },                titleOfResearchProject: {                    validators: {                        stringLength: {                            min: 5,                            message: 'Please Enter the title with minimum 5 letters length'                        },                        notEmpty: {                            message: 'Please Enter title of your project'                        }                    }                },以下是上述頁面的屏幕截圖,該頁面位于XAMPP的htdocs文件夾中。index.htmlpublic開發人員的控制臺未顯示任何錯誤,如下所示;
查看完整描述

2 回答

?
鴻蒙傳說

TA貢獻1865條經驗 獲得超7個贊

您的代碼有一些斷開的鏈接,并且您沒有在文檔“ready”上初始化驗證函數,也不應該在對象加載之前初始化驗證器。我已經在下面修復了這些問題:validateForm



    <!DOCTYPE html>

    <html>

    <head>

    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">

    <meta content="utf-8" http-equiv="encoding">

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <!-- fixed broken link -->

    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/css/bootstrapvalidator.min.css" rel="stylesheet">

    <script src="https://code.jquery.com/jquery-3.4.0.min.js"></script>

    <script src='http://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/js/bootstrapvalidator.min.js'></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <!-- fixed broken link -->


    </head>

    <body>

    <div id="wrapper">


        <div id="page-wrapper">

            <div class="container-fluid">

                <!-- Page Heading -->

                <div class="row" id="main" >


                    <!-- BEGIN Bootstrap form testing-->

                    <form class="form-horizontal" id="validateForm" method="POST" onsubmit="return false">

                        <div class="row">

                            <div class="col-md-offset-1 col-md-4">


                                <div class="form-group">

                                    <label class="control-label">Select your patient sets:</label>

                                    <select name="patientSets" class="form-control" >

                                        <option value=" " >Please select patient set</option>

                                        <option>PS1</option>

                                        <option>PS2</option>

                                    </select>

                                </div>




                                <div class="form-group">

                                    <label class="control-label">Description of research project:</label>

                                    <textarea class="form-control" name="descriptionOfResearchProject" placeholder="Enter your description here...."></textarea>

                                  </div>



                            </div>

                            <div class="col-md-offset-1 col-md-4">

                                <div class="form-group">

                                    <label class="control-label">Title of your research project:</label>

                                    <input name="titleOfResearchProject" placeholder="Enter your title here...." class="form-control" type="text">

                                  </div>


                                  <div class="form-group">

                                    <label class="control-label">Intended use:</label>

                                    <select name="intendedUse" class="form-control" >

                                        <option value=" " >Please select one</option>

                                        <option>test1</option>

                                        <option>test2</option>

                                    </select>

                                </div>




                            </div>

                        </div>


                        <button class="btn btn-success" id="conceptsButton">Request Data</button>




                        </form>

                 </div>


        </div>

        <!-- /#page-wrapper -->

    </div><!-- /#wrapper -->




    <script type="text/javascript">

            //Initialize function when document 'is ready'

            $(document).ready(function() {

        //BEGIN FORM Validations

            $('#validateForm').bootstrapValidator({

          feedbackIcons: {

            valid: 'glyphicon glyphicon-ok',

            invalid: 'glyphicon glyphicon-remove',

            validating: 'glyphicon glyphicon-refresh'

        },

        fields: {


            patientSets: {

                validators: {

                    notEmpty: {

                        message: 'Please select a patient set'

                    }

                }

            },

            titleOfResearchProject: {

                validators: {

                    stringLength: {

                        min: 5,

                        message: 'Please Enter the title with minimum 5 letters length'

                    },

                    notEmpty: {

                        message: 'Please Enter title of your project'

                    }

                }

            },


            descriptionOfResearchProject: {

                validators: {

                    stringLength: {

                        min: 15,

                        max: 100,

                        message: 'Please enter at least 15 characters and no more than 100'

                    },

                    notEmpty: {

                        message: 'Please Enter Description'

                    }

                }

            },

            intendedUse: {

                validators: {

                    notEmpty: {

                        message: 'Please select one option'

                    }

                }

            },

        }

    });


            //END FORM Validations

    });

            //END FORM Validations

        </script>

    </body>

    </html>


查看完整回答
反對 回復 2022-08-04
?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

這是因為您嘗試在對象加載之前初始化驗證程序。將腳本移到validateForm</body>



查看完整回答
反對 回復 2022-08-04
  • 2 回答
  • 0 關注
  • 103 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號