升级到jquery 3.1.1后我刚遇到一个错误管理员可以单击“编辑用户”按钮,该按钮将启动模式并传播具有从数据库中获取的用户数据的输入字段。输入字段选择器在第一个功能中。data.email.val(result.email);或users.add_edit_data.email.val(result.email)不会更改ID为ID的字段的值。没有控制台错误。结果已正确获取,我可以通过记录它console.log(result.email)。通过$('#email').val(result.email);按预期方式直接分配值。我不确定此代码在升级之前是否可以正常工作,希望朝正确的方向前进。不太确定如何从现在开始调试它。/** * Helps match input fields with values and general assignments */users.add_edit_data = { username: $('#username'), email: $('#email'), first_name: $('#first_name'), last_name: $('#last_name'), address: $('#address'), phone: $('#phone'), password: $('#password'), fb_id: $('#fb_id'), country: $('#country'), city: $('#city'), confirm_password: $('#confirm_password'), button: $('#btn-add-user')};/** * Gets user details and propogates it in the input fields * * @param {int} user_id */users.edit_user = function (user_id) { $('#user-id').val(user_id); var modal = $('#modal-add-edit-user'); var data = users.add_edit_data; var modal_title = modal.find('.modal-title'); var modal_body = modal.find('.m-body'); var ajax_loading = modal.find('.ajax-loading'); //data.button.attr('onclick', 'users.update_user();'); neou_cms.remove_error_messages(); modal.modal('show'); modal_title.text($_lang.processing_loading); modal_body.hide(); ajax_loading.show(); console.log(users.add_edit_data.username); $.ajax({ type: 'POST', url: base_path + 'access_control/get_user_details', dataType: 'json', data: { user_id: user_id }, success: function (result) { if (result.status === 'error') { toastr.error(result.msg); } });};在开发工具中键入users.add_edit_data.username.val('12312');yields r.fn.init {},我100%确定ID用户名为id的输入存在且是唯一的。我有一个旧的jquery版本的网站的旧工作副本,并键入与上述相同的内容,r.fn.init [input#username.form-control]并更改了值。
2 回答

SMILET
TA贡献1796条经验 获得超4个赞
您的对象stmt如下:
stmt = {
defs: {
username: $('#hw')
}
}
因此,您可以使用以下方式更改username属性的值: stmt.defs.username = 'Hello world';
如果要更新input元素的值,请使用$('#hw').val('Hello World')
添加回答
举报
0/150
提交
取消