2015-02-07 64 views
-2

我有一個單一的屬性的形式,我想提交表單上更改唯一的屬性的值,但不知何故改變事件沒有啓動。 這裏是我的代碼表單提交更改輸入字段的值

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

 
$('#user_profilepic').change(function(){ 
 
\t $('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>

在此先感謝

+0

你的HTML運行jQuery代碼之前加載分享您的HTML,Fiddle會更好。 – Farhan 2015-02-07 09:03:01

+0

我已經粘貼了我的html代碼上面 – Mr94 2015-02-07 09:10:06

回答

0

這裏是工作的代碼jsfiddle 確保通過$(document).ready()

+0

非常感謝.... – Mr94 2015-02-07 13:01:33