【发布时间】:2011-12-05 14:01:17
【问题描述】:
我正在尝试在 coffeescript/jquery 中实现以下内容
-> 当用户输入时,检查文本框是否为空(或有文本“写评论...”),隐藏“添加评论”按钮。否则显示“添加评论”按钮
但是,我面临一个问题,即从文本框返回给我的 val() 总是落后一个按键。
例如,如果我在框中输入“sad”,target.val() 只会返回“sa”。
如何在我键入时在文本框中获取最新的值?
我的实现如下
events:
"keydown .comment_area": "commenting"
commenting: (e) ->
target = @$(e.currentTarget)
//target.val() is not returning me the latest character entered in the box
if $.trim(target.val()) == "" or $.trim(target.val()) =="Write a comment..."
//hide the 'add' button
@$('.add_comment').hide()
else
//show the 'add' button
@$('.add_comment').show()
【问题讨论】:
标签: javascript jquery textbox coffeescript