2014-09-05 246 views
1

不顯示出於某種原因,我的輸入值將不會在控制檯顯示...輸入值在控制檯

這裏是我的代碼,

HTML:

<tr class="area"><td class="icon"></td> 
    <td class="title"> 
     <div> 
     User: <input id="inputUser" type="text" style="margin-top: 2px;margin-left:2px"></input> 
     Ammount: <input id="inputAmmount" type="text" style="margin-top:2px;margin-left:2px; padding-right: 0px"></input> 
     </div> 
     <td><a class="btn" style="margin-top:3px">Submit</a></td> 
    </td>   
</tr> 

JQUERY

$('.btn').click(function(){ 
     console.log("click detected"); 
     var userID = $('#inputUser').val(); 
     var ammount = $('#inputAmmount').val(); 
     console.log(userID); 
}); 

控制檯正在成功輸出「點擊檢測」,但對於用戶標識,它不顯示任何內容。

+2

你定義的變量'user',但你嘗試登錄'userID' ... – Ian 2014-09-05 22:10:19

+1

控制檯。日誌(用戶)也許.. userId不在那裏。 – 2014-09-05 22:10:27

+0

我的錯誤是在複製粘貼過程中出錯,它仍然不適用於我 – tinthetub 2014-09-05 22:17:09

回答

0

你的代碼工作對我來說: http://jsfiddle.net/1reLtunc/

我可以推薦的唯一的事情是,你檢查,當你創建你確信你的HTML已經呈現,而不是作爲$('.btn').click事件監聽器通過ajax加載。

如果它正在通過ajax加載,您將希望在ajax調用完成後重新綁定事件監聽器。

另外,確保你換你$('.btn').click事件偵聽器在$(document).ready(function() { /* your code here */ })或簡寫equivilent:$(function() { /* your code here */ })