表格提交输入字段的变化值

时间:2015-02-07 08:41:13

标签: jquery ruby-on-rails

我有一个带有单个属性的表单,我希望在更改唯一属性的值时提交表单但不知何故更改事件未启动。 这是我的代码



function triggerClick(){
	$('#user_profilepic').trigger('click');
};

$('#user_profilepic').change(function(){
	$('form#updateAvatar').submit();
});

#updateAvatar{
  display: none;
  }

<form id="updateAvatar" class="simple_form edit_user" method="post" accept-charset="UTF-8" action="/edit/updateAvatar" enctype="multipart/form-data" novalidate="novalidate">
  <div class="form-group file optional user_profilepic">
  <label class="file optional control-label" for="user_profilepic">Profilepic</label>
  <input id="user_profilepic" class="file optional" type="file" name="user[profilepic]">
  </div>
  <input type="submit" value="Update User" name="commit">
</form>
&#13;
&#13;
&#13;

提前致谢

1 个答案:

答案 0 :(得分:0)

以下是工作代码jsfiddle$(document).ready()

运行jQuery代码之前,请确保已加载html
相关问题