2013-05-29 80 views
1

我如何包括轨道复选框以下功能:check_box_tag onclick事件包括JavaScript

如果复选框,点击输入框显示,否则不显示输入框。以下不起作用。

= check_box_tag 'update',:onclick=>$('#inputBox')[this.checked ? "show" : "hide"]();

+0

你的方法调用必须是一个字符串::的onclick => “myMethod的();” http://stackoverflow.com/questions/9400736/passing-rails-variable-in-a-onclick-function-of-check-box-tag – dmoss18

回答

2

像这样:

= check_box_tag 'update', :onclick => "$('#inputBox')[this.checked ? 'show' : 'hide']();" 
+0

我点击复选框,什么都没有发生。如果inputBox在复选框代码之后,这有什么关系吗? – Bruno

0
= check_box_tag 'update',:onclick=>'$(this).checked() ? $("#inputBox").show(): $("#inputBox")hide();'