我遇到以下问题。由于有许多业务规则,我决定将这些功能作为js自动更新。Javascript无法获得运营价值
在我看来,我有: 这是一个表
(<%= javascript_include_tag 'people'%>)
<th>Name</th>
<th>Money</th>
<th>Money Comment</th>
</tr>
<% @counter = 0 %>
<% @people.each do |p| %>
<% @counter += 1 %>
<tr>
<%= form_for(:p) do |f| %>
<th><%= f.label(p.name) %></th>
<th><label for="<%= "money_" + @counter.to_s %>"> <%= f.select(:money, 1..10, :selected => p.money)%></label></th>
<th><label for="<%= "comment_" + @counter.to_s %>"> <%= f.label(p.money_comment, :disabled => 'disabled')%></label></th>
<% end %>
<% end %>
内,在JavaScript函数如下:
function change_people() {
money1 = $('money_1').getValue();
if (money1 == 10) {
$('comment_2').setValue("I know what you're doing you mofo");
}
else {
$('comment_2').setValue("");
}
}
document.observe('dom:loaded', function() {
change_people();
$('money_1').observe('change', change_people);
});
,但由于某种原因,它不断告诉我没有关系不知道我的意思是“money_1”。我检查html源代码并编译视图,我是否在js中错误地引用了元素?
感谢您的帮助!
请编辑你已经包括了代码使用的代码标记({})。 – 2011-01-22 17:43:16