我的页面上有一个选择输入。此选择输入显示/隐藏表单中的字段。这一切工作正常。但问题是,如果我提交表单并且缺少一些必要的字段,那么事后它不会将select设置为正确的值。我只是不能让嵌入的红宝石工作!它不断逃避整个事情...在这里我的代码:ERB不会在JavaScript脚本中执行
$(document).ready(function() {
$("#profile_sex").val('<%= @profile.sex %>')
$("#profile_sex").change(function(){
($(this).val() == "Frau") ? $('#form-female').show() : $('#form-female').hide();
($(this).val() == "Mann") ? $('#form-male').show() : $('#form-male').hide();
if ($(this).val() == "Paar") {
$('#form-female').show();
$('#form-male').show();
}
});
});
为什么不工作这??? 我没有得到任何错误或任何它只是将值设置为“<%= @ profile.sex =>” 我是googling和搜索堆栈溢出和railscasts,rails API,一切。我很困惑...
感谢您的帮助。
更妙的是,使用@ profile.sex.inspect或@ profile.sex.to_json,以防止任何杂散引号破坏您的脚本。 – jdeseno 2010-08-11 22:52:58
得到它的工作,谢谢。 @jdeseno: 会做。 – KimJongIl 2010-08-12 08:45:42