| <html> <head> <title>Ajax List Demo</title> <%= javascript_include_tag "prototype" %> </head> <body> <h3>Add to list using Ajax</h3> <%= form_remote_tag(:update => "my_list", :url => { :action => :add_item }, :position => "top" ) %> New item text: <%= text_field_tag :newitem %> <%= submit_tag "Add item with Ajax" %> <%= end_form_tag %> <ul id="my_list"> <li>Original item... please add more!</li> </ul> </body> </html> |
![]() 图4.在增加任何项前 |
| class ListdemoController < ApplicationController def index end def add_item render_text "<li>" + params[:newitem] + "</li>" end end |
![]() 图5.添加几个新的列表项之后 |