[img]http://www.iteye.com/upload/attachment/135954/fa4924e9-1c50-32c2-ba46-5094969e75a3.png[/img]
我不说其它的话了,直接上代码:
页面_message:
表单输入页面new.html.erb:
css代码:
ICON图标来自这个网站:[url]http://www.famfamfam.com/lab/icons/silk/[/url]
相关链接:[url]http://livevalidation.com/[/url]
[url]http://dmix.ca/2009/07/simple-live-validations-in-rails/[/url]
[url]http://plugins.jquery.com/project/validate[/url]
[url]http://github.com/augustl/live-validations/tree/master[/url]
我不说其它的话了,直接上代码:
class LiveValidationsController < ApplicationController
def validate_username
if params[:username].length > 3
@user = User.find_by_username(params[:username])
if @user.nil?
@message = "<img src='/images/accept.png' alt='Valid Username' />
else
@message = "<img src='/images/cross.png' alt='Invalid Username' /> Name taken"
end
else
@message = ""
end
render :partial => "message"
end
end
页面_message:
<%= @message %>
表单输入页面new.html.erb:
Username <%= f.text_field :username %><span id="username_message" class="live_validation"></span>
<%= observe_field :form_username,
:url => { :controller => :live_validations, :action => :validate_username },
:frequency => 0.5,
:update => :username_message,
:with => "username" %>
css代码:
.live_validation{margin-left:3px;background:#EEEE00;font-size:90%;}
.live_validation img{vertical-align:middle}
ICON图标来自这个网站:[url]http://www.famfamfam.com/lab/icons/silk/[/url]
相关链接:[url]http://livevalidation.com/[/url]
[url]http://dmix.ca/2009/07/simple-live-validations-in-rails/[/url]
[url]http://plugins.jquery.com/project/validate[/url]
[url]http://github.com/augustl/live-validations/tree/master[/url]