<%= simple_form_for @user, :url => create_performer_path do |f| %>
<%= f.input :name, :label => "Model Name" %></p>
<%= f.input :email %></p>
<%= f.input :password %></p>
<%= f.input :password_confirmation, :id =>"password" %></p>
<%= f.hidden_field_tag :password_next ,:id=>"password_next"%>
<p><%= f.submit "Save" ,:onclick=>"value"%></p>
<% end %>
这是我用来使用 devise 创建用户的 rails 表单。现在这是我在同一页面中编写的脚本,用于将 password_confirmation 值复制到 password_next 值。
<script type="text/javascript">
function value
{
document.form.password_next.value=document.form.password.value
}
<script>
但这不起作用。我究竟做错了什么?
这里是纯 html 输出函数值 { document.form.password_next.value=document.form.password.value } Create Performer
<form accept-charset="UTF-8" action="/create_performer" class="simple_form new_user" enctype="multipart/form-data" id="new_user" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="dF4uCaq0ymIoc5ooypVt3ohYlD/4+95ho28hNuP6kfw=" /></div>
<div class="control-group string optional user_name"><label class="string optional control-label" for="user_name">Model Name</label><div class="controls"><input class="string optional" id="user_name" name="user[name]" type="text" /></div></div></p>
<div class="control-group email optional user_email"><label class="email optional control-label" for="user_email">Email</label><div class="controls"><input class="string email optional" id="user_email" name="user[email]" type="email" value="" /></div></div></p>
<div class="control-group password optional user_password"><label class="password optional control-label" for="user_password">Password</label><div class="controls"><input class="password optional" id="user_password" name="user[password]" type="password" /></div></div></p>
<div class="control-group password optional user_password_confirmation"><label class="password optional control-label" for="user_password_confirmation">Password confirmation</label><div class="controls"><input class="password optional" id="user_password_confirmation" name="user[password_confirmation]" type="password" /></div></div></p>
<div class="controls performer_check_box">
<label class="string optional control-label" for="user_roles">Roles</label>
<input checked="checked" id="user_role_ids_" name="user[role_ids][]" type="checkbox" value="2" />
performer<br />
</div>
<div class="control-group string optional user_performer_first_name"><label class="string optional control-label" for="user_performer_attributes_first_name">User name</label><div class="controls">
<input class="string optional" id="user_performer_attributes_first_name" name="user[performer_attributes][first_name]" type="text" /></div></div></p>
<label class="string optional control-label" for="user_performer_attributes_location">Location</label>
<select id="user_performer_attributes_location_id" name="user[performer_attributes][location_id]"><option value="">Location</option>
<option value="1">US</option>
<option value="2">Canada</option>
<option value="3">UK</option></select>
<div class="control-group file optional user_performer_avatar"><label class="file optional control-label" for="user_performer_attributes_avatar">Avatar</label><div class="controls"><input class="file optional" id="user_performer_attributes_avatar" name="user[performer_attributes][avatar]" type="file" /></div></div></p>
<div class="control-group file optional user_performer_photo_id"><label class="file optional control-label" for="user_performer_attributes_photo_id">Photo</label><div class="controls"><input class="file optional" id="user_performer_attributes_photo_id" name="user[performer_attributes][photo_id]" type="file" /></div></div></p>
<div class="control-group file optional user_performer_profile_thumb"><label class="file optional control-label" for="user_performer_attributes_profile_thumb">Profile thumb</label><div class="controls"><input class="file optional" id="user_performer_attributes_profile_thumb" name="user[performer_attributes][profile_thumb]" type="file" /></div></div></p>
<div class="control-group file optional user_performer_profile_gif"><label class="file optional control-label" for="user_performer_attributes_profile_gif">Profile gif</label><div class="controls"><input class="file optional" id="user_performer_attributes_profile_gif" name="user[performer_attributes][profile_gif]" type="file" /></div></div>
<select id="user_performer_attributes_white_label_id" name="user[performer_attributes][white_label_id]"><option value="">Owner</option>
<option value="1">master</option>
<option value="2">dio888</option>
<option value="3">avm_studio</option></select>
<input id="password_next" name="user[password_next]" type="hidden" />
<p><input name="commit" onhover="value" type="submit" value="Save" /></p>
</form>