dynamic f.collection_select我怎样才能调用javascript函数
问题描述:
这是我的代码,在这个我想调用一个Java脚本函数的一些条件就像比如调用hi()函数和a = 2比调用hello()功能dynamic f.collection_select我怎样才能调用javascript函数
<%= f.collection_select :ser_id, @ser, :id, :name, :prompt => true -%>
JavaScript函数中
function hi()
{
alert("hi");
}
function hello()
{
alert("hello");
}
所以现在给我一些想法,我怎样才能根据给定的条件调用这些运作。
答
尝试:
<% fun_name = "" %>
<% fun_name = (a==1 ? "eval('hi()')" : "eval('hello()')") if a==1 || a==2 %>
<%= f.collection_select :ser_id, @ser, :id, :name, :prompt => true, {:onchange => fun_name } -%>
就以编辑答案看看。 – Vik 2012-04-06 11:16:16