2015-08-28 63 views
6

您好我有一個引導模式,裏面有一個輸入字段。從模態輸入獲取價值

<input type="text" name="quota" class="form-control" id="quotas" value="'.$storagequota.'" maxlength="20" > 

還我有一個按鈕,點擊它時,調用一個函數,所以我可以輸入字段

function getQuota(){ 
    quota = $("#quotas").val(); 
    alert(quota); 
} 

問題的價值在於,我不能讓用戶鍵入的值。 奇怪的是,我有另一個模式在另一個頁面,以相同的方式工作。 有人可以幫忙嗎? 在此先感謝

+0

的ID,然後才能提供一個小提琴? –

+0

https://jsfiddle.net/6n9jd1nk/2/ –

+0

是否有多個元素在你的頁面中具有相同的ID quotas'? – RRK

回答

0

您的代碼是正確的。

只需在head標籤中寫入JS function標籤。

這裏是你的代碼

<html>  
<head> 
    <script> 
     function testFun() { 
      quota = $("#quotas").val(); 
      alert(quota); 
     } 
    </script> 
</head> 

<body> 
    <div id="admin" class="modal fade" role="dialog"> 
     <div class="modal-dialog"> 
      <!-- Modal content--> 
      <div class="modal-content animated bounceInDown"> 
       <div class="modal-header"> 
        <button type="button" class="close" data-dismiss="modal">&times;</button> 
         <h4 class="modal-title">Settings</h4> 

       </div> 
       <div class="modal-body"> 
        <ul class="nav nav-tabs"> 
         <li class="active"><a href="#tab1" data-toggle="tab">Quota</a> 

         </li> 
        </ul> 
        <div class="tab-content"> 
         <div class="tab-pane active" id="tab1"> 
          </br> 
          <div id="table" class="col-lg-12"></div> 
          <label for="Quota">Quota</label> 
          <div class="input-group form-group"> 
           <input type="text" name="quota" class="form-control" id="quotas" value="10" maxlength="20"> 
           <div class="input-group-addon input-group-btn-custom "> <span id="type">Gb</span> 
           </div> 
          </div> 
         </div> 
         </br> 
         </br> 
         <button type="submit" class="btn btn-primary" onclick="testFun()" id="admin">Submit</button> 
        </div> 
       </div> 
       <div class="modal-footer"> 
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> 
       </div> 
      </div> 
     </div> 
    </div> 
</body> 

</html> 

Working Demo

+0

問題是我有一個主文件,我有我的所有功能和一個文件,有我的主頁,我在每個頁面中調用它。我把它放在兩個但仍然是相同的。我不知道我會做什麼 –

+0

然後只加載該文件的頭部分。 –

+0

我加載它的頭部 –

7

只要把模態的ID輸入

$("#registration_modal #useremail").val().trim()