占位符宽度函数抛出Uncaught TypeError: Cannot read property 'lengt
Placeholder width function throws Uncaught TypeError: Cannot read property 'length' of null
我是Js的新手,我不能确定错误的来源:
我正在使用一个函数来自动调整输入字段的大小到占位符的大小;代码工作得很好afaik但是开发工具告诉我"不能读取null属性'length' "
我有点迷失在这一点上:我试图改变数据(JSON)的类型没有成功,检查是否有与元素ID相关的东西;我已经看过一些类似的问题,但还没能找出问题的症结。
这是一段实际代码
var input = document.querySelectorAll('input');
for(i=0; i<input.length; i++){
input[i].setAttribute('size',input[i].getAttribute('placeholder').length);
}
radio
按钮没有占位符,所以getAttribute('placeholder')
返回null
。
你需要调整你的选择器,只抓取input[type='text']
(或超级安全,input[placeholder]
)。
相关文章:
- 未捕获TypeError: Cannot read property 'geocode'未定义的'
- SailsJs中的错误.TypeError: Cannot read property '的定义
- 未捕获的TypeError: Cannot read property 'top'的定义
- 未捕获的TypeError: Cannot read property '未定义的数据表
- 未捕获的TypeError: Cannot read property 'timing'的定义
- 未捕获的TypeError: Cannot read property 'checked'零
- 未捕获的TypeError: Cannot read property 'top'在引导中单击导航栏时未
- Extjs5 treepanel [Uncaught TypeError: Cannot read property &
- TypeError: Cannot read property 'submit'添加到购物车'
- 添加自定义jquery.验证方法导致Uncaught TypeError: Cannot read property &
- Vue 2和Vue- resource [Cannot read property 'get'未定义的(
- asp:textbox Uncaught TypeError: Cannot read property 'va
- TypeError: Cannot read property 'search' of undefine
- 读取json时出错未捕获类型错误:Cannot read property 'output'的定义
- 未捕获的TypeError: Cannot read property 'current'在选择任何选项
- 未捕获的TypeError: Cannot read property '3'的定义
- jquery-ui.js:12443未捕获的TypeError: Cannot read property 'a
- jquery Uncaught TypeError: Cannot read property 'left
- 未捕获类型错误:Cannot read property 'print'的定义
- TokenInput + Uncaught TypeError: Cannot read property 't