我有以下HTML代码:
<input id="user_current_password" name="user[current_password]" size="20" type="password" style="display: none;">我想要删除size属性。我已经尝试过这样的方法:
$("#user_current_password").removeAttr("size")
$("#user_current_password").attr("size","auto")
$("#user_current_password").attr("size","")但是它总是给我错误: DOMException:未能在‘HTMLInputElement’上设置' size‘属性:提供的值是0,这是一个无效的大小。
谢谢
发布于 2014-12-16 19:10:44
这应该可以解决这个问题,只使用javascript:
var a = document.getElementById('user_current_password');
a.setAttribute('size','auto'); // <<< set size as wished或者,移除它:
a.removeAttribute('size');请注意将此代码放置在
window.onload = function() { /* code */ }因为必须加载DOM才能让代码找到元素
https://stackoverflow.com/questions/27512073
复制相似问题