我正在使用 Ruby on Rails 3,我想从表单文本字段检索一个值,并使用 RJS 在另一个表单文本字段中设置该值,如下所示(或以更好的方式!):
update_page_tag do |page|
page.event.observe('text_field1_css_id', 'keyup') do |element|
element << ... # Get and set a '@variable' value using the value in the
# HTML textarea tag with id = 'text_field1_css_id'. The
# '@variable' value should be accessible from the
# 'element.replace_html' method stated below
element << ...
...
element.replace_html (:text_field2_css_id), @variable.inspect
end
end
如何使用Prototype框架做到这一点?
最佳答案
在原型(prototype)中:
// /public/application.js
$('text_field_1_css_id').observe('keyup',function(event){
$('text_field2_css_id').setValue($F(event.element));
});
<小时/>
对于其他可能感兴趣的人,如果您使用 jquery,您可能可以使用:
// /public/application.js
$('#text_field_1_css_id').keyup(function(){
$('#text_field2_css_id').value($(this).value());
});
关于javascript - 从表单文本字段检索值并使用 RJS 在另一个表单文本字段中设置该值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6267088/