【发布时间】:2014-01-13 09:06:24
【问题描述】:
我正在尝试将 JS 函数绑定到文本字段(“文本”类型的输入)。使用 JQuery 2.0.2 和 Rails 3.1 我在位于 assets/javascripts 的 .js.coffee 文件中执行此操作:
window.test_questions = {}
window.test_questions.bind_input = ->
$('#question_content').on 'input', ->
// do something
然后在位于views\TheRightController 文件夹中的.js.erb 中运行:
$('#new_question').html('<%= escape_javascript(render("new_question_form")) %>');
test_questions.bind_input();
#question_content 在部分渲染之前不存在于页面上。我担心bind_input()会在渲染完成之前运行,找不到#question_content并没有绑定任何东西。
我不是 100% 这是一个问题(我的代码目前正在运行),但我担心如果我在其他地方使用“更重”的渲染它会中断。
我的担心是徒劳的吗? 有什么方法可以确保渲染完成没有错误,然后才执行下一行。
【问题讨论】:
标签: javascript jquery ruby-on-rails ajax render