在我的Rails应用程序中,我有一个Post
模型。
我正在使用coffeescript使帖子形式更加动态。
在中posts.coffee
,我有:
$(document).ready ->
text_max = 140
$('#character_count').html text_max + ' characters remaining'
$('#post_short_copy').keyup ->
text_length = $('#post_short_copy').val().length
text_remaining = text_max - text_length
$('#character_count').html text_remaining + ' characters remaining'
return
return
这真的很好。
现在,我需要在此代码内插入if语句,仅执行$('#character_count').html text_max + ' characters remaining'
if $('#post_short_copy').is(':empty')
。
我尝试了以下代码:
$(document).ready ->
text_max = 140
if $('#post_short_copy').is(':empty') {
$('#character_count').html text_max + ' characters remaining'
}
$('#post_short_copy').keyup ->
text_length = $('#post_short_copy').val().length
text_remaining = text_max - text_length
$('#character_count').html text_remaining + ' characters remaining'
return
return
但这返回一个错误:
SyntaxError: [stdin]:7:3: unexpected if
任何想法如何正确地在coffeescript中实现if语句?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句