2014-09-05 107 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 */ })