2015-04-03 76 views
0

我試圖添加一個模式到我的網站,當窗體的名稱字段留空時出現,以通知用戶。引導模式:未定義

我至今是:

<div id="myModal-winner" class="modal fade"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
       <h4 class="modal-title">There is a Problem!</h4> 
      </div> 
      <div class="modal-body"> 
       <p>Please Enter Name of Winner.</p> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-info" data-dismiss="modal">Ok</button> 
      </div> 
     </div> 
    </div> 
</div> 

,應該使該模式的出現,如果名稱爲空的JS:

//when user clicks on the "submit" button 
    form.submit({point: point}, function (event) { 
     //prevent the default form behavior (which would refresh the page) 
     event.preventDefault(); 

     //form validation 
     if(!$("input[name=name]", this).val()) { 
      $("#myModal-winner").modal('show'); 
     } 

     //put all form elements in a "data" object 
     var data = { 
      name: $("input[name=name]", this).val(), 
      address: $("textarea[name=address]", this).val(), 
      about: $("textarea[name=about]", this).val(), 
      month: $("select[name=month]",this).val(), 
      year: $("select[name=year]",this).val(), 
      lat: event.data.point.overlay.getPosition().lat(), 
      lon: event.data.point.overlay.getPosition().lng() 
     }; 
     trace(data) 

     //send the results to the PHP script that adds the point to the database 
     $.post("addwinner.php", data, tidy_maps.saveStopResponse, "json"); 

但控制檯將返回:Uncaught TypeError: undefined is not a function,就行了:

$("#myModal-winner").modal('show'); 

這是表格,並提交按鈕:

<div class="winner-add"> 
<form class="form-horizontal winner-form" method="post" style="display: none" action="addwinner.php"> 
    <h4>Add Winner</h4> 
    <img src="" > 
    <fieldset> 
     <label for="name"> 
      <span>Event Name :</span> 
      <input id="name" type="text" name="name" placeholder="Enter Name of Winner" /> 
     </label> 
     <label for="address"> 
      <span>Description :</span> 
      <textarea id="address" name="address" placeholder="Address of Winner"></textarea> 
     </label> 
     <label for="about"> 
      <span>Description :</span> 
      <textarea id="about" name="about" placeholder="Details of Award"></textarea> 
     </label> 
     <label for="image"> 
      <span>Upload a Photo:</span> 
      <input type="file" id="image" name="image" /> 
     </label> 
     <hr> 

     <div class="form-actions"> 
      <input name="Save" type="submit" class="btn btn-success btn-sm" value="Save"> 
     </div> 
    </fieldset> 
</form> 
+0

你能表現出更多的JS和HTML的?越多越好。特別是,我們無法看到表單,提交表單的按鈕,JS按鈕綁定或表單提交等等。所有這些都可以幫助我們排除故障而無需猜測。 – 2015-04-03 23:20:46

+0

它看起來像jquery沒有加載。 – Jarod 2015-04-03 23:24:21

+0

JS中的'form'來自哪裏,在你粘貼的代碼出現之前,你是否設置了它? – 2015-04-03 23:27:47

回答

1

我同意Joard,它看起來像jQuery沒有被加載。確保您的腳本標記上方有<script src="path_to_jquery"></script>以進行引導。

或者,如果你沒有jQuery的項目文件夾,你可以抓住它關閉互聯網:<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

1

這是一個jQuery問題。我在「MyModal影帝」這裏有一個拼寫錯誤:

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $("#myModal-winner").modal('hide'); 
    }); 
</script> 

而且,之前的jQuery加載引導造成2之間有衝突,所以現在我有jQuery的引導之前加載。

+0

是的,jQuery必須始終在Bootstrap之前加載。很高興你把它整理出來。 – 2015-04-03 23:32:51