"password" %> "password_next"%> "value"%>-6ren">
gpt4 book ai didi

javascript - 在 rails 中使用 jquery 提交之前,将值从输入框复制到隐藏字段

转载 作者:行者123 更新时间:2023-11-30 06:29:13 24 4
gpt4 key购买 nike

<%= 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 }创建表演者

<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="&#x2713;" /><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>

最佳答案

脚本:

<script type="text/javascript">
function copy_pwd_confirmation()
{
document.form.password_next.value=document.form.password.value;
}
<script>

在密码确认的blur上调用此方法,

 <%= f.input :password_confirmation, :id =>"password" ,  onblur: "copy_pwd_confirmation()" %></p> 

编辑:

你能试试 jquery insted of javascript..

  $("#password_next").value($("#user_password_confirmation").value());

关于javascript - 在 rails 中使用 jquery 提交之前,将值从输入框复制到隐藏字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18960177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com