2014-01-19 45 views
1

收盤前我使用的例子在這裏建立自己的狀態:http://bootply.com/60244引導模式窗體驗證

我的JavaScript似乎並沒有被調用等形式,只要我點擊「保存更改」關閉。任何想法,將不勝感激

這裏是我的代碼

<!-- Modal --> 
    <div class="modal hide fade" id="mailerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
      <h3_pink id="myModalLabel">Request a Mailer Bag</h3_pink> 
     </div> 
     <div class="modal-body"> 
      <h3_pink> </h3> 
      <form method="post" id="FormMailer" action="soon2.php"> 
       <input type="hidden" name="FormMailer" value="1"> 
       <table> 
        <tbody> 
         <tr><td>First Name</td><td><input type="text" name="contact_fname" id="contact_fname" style="width:90%"><span class="hide help-inline">This is required</span></td> 
         <td>Last Name</td><td><input type="text" name="contact_lname" id="contact_lname" placeholder="Last Name" style="width:90%"><span class="hide help-inline">This is required</span></td></tr> 
         <tr><td>Email Address</td><td colspan="3"><input type="text" name="contact_email" id="contact_email" placeholder="Email Address" style="width:90%"><span class="hide help-inline">This is required</span></td></tr> 
         <tr><td>Street1</td><td colspan="3"><input type="text" id="contact_street1" name="contact_street1" placeholder="Street" style="width:90%"><span class="hide help-inline">This is required</span></td></tr> 
         <tr><td>Street2</td><td colspan="3"><input type="text" id="contact_street2" name="contact_street2" placeholder="Street" style="width:90%"></td></tr> 
         <tr><td>City</td><td colspan="3"><input type="text" id="contact_city" name="contact_city" placeholder="City" style="width:90%"><span class="hide help-inline">This is required</span></td></tr> 
         <tr><td>Zip</td><td colspan="3"><input type="text" name="zip" id="zip" style="width:90%"><span class="hide help-inline">This is required</span></td></tr> 
         <tr><td>Message</td><td colspan="3"><textarea id="contact_message" name="contact_message" style="width:90%"></textarea></td></tr> 
        </tbody> 
       </table> 
      </form> 
     </div><!-- /.modal-body --> 
     <div class="modal-footer"> 
      <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> 
      <button class="btn btn-primary" data-dismiss="modal" id="FormMailerSubmit">Save changes</button> 
     </div> 
    </div><!-- /.modal --> 
    <!-- Modal Ends --> 

    <script src="https://code.jquery.com/jquery.js"></script> 
    <script src="/soon/js/bootstrap.js"></script> 
    <link rel="stylesheet" href="soon/styles/bootstrap.min.css" media="screen" /> 
    <link rel="stylesheet" href="soon/styles/bootstrap-responsive.min.css" media="screen" /> 
    <link rel="stylesheet" href="soon/styles/style.css"/> 
    <link rel="stylesheet" href="soon/styles/style_responsive.css"/> 

    <script type='text/javascript'> 
     $(document).ready(function() { 
      $('#FormMailerSubmit').click(function(){ 
      if ($('#contact_fname').val()==="") { 
        // invalid 
        $('#contact_fname').next('.help-inline').show(); 
        return false; 
       } 
       else { 
        // $('#FormMailer').submit(); 

        return true; 
       } 
      }); 
     });   
    </script> 

回答

1

其由於按鈕上的data-dismiss="modal"屬性閉幕。刪除它,它不會關閉。如果您需要關閉它在你的JS,你可以使用modal.modal('hide');

+0

我上面鏈接的代碼示例展示了數據駁回=」模式「保存更改按鈕代碼示例...但只是爲了安全起見,我刪除了data-dismiss =」modal「,它仍然關閉。我可能會在我的js文件中產生衝突,導致我的嵌入式js根本沒有被執行。 – user3211239

+0

我實際上認爲我之前有過使用模式中的2個按鈕的問題。取而代之,如果嘗試使用保存更改按鈕的定位標記,看看是否有幫助。 –

0

好吧,首先第一

  • 東西在所有按鈕指定類型 - 默認類型應該是一個 submit按鈕,而不是一個普通按鈕。

  • 您可能想要在模態hide事件中進行驗證。如果 數據無效,則從事件處理程序返回false,並且其 將不會關閉。這只是讓你的事件是否從差一點/取消按鈕或預期 提交按鈕標識 的小問題....