nextSibling.focus()报错的问题
2024-08-28 13:11:13
<body> <div> <input type="button" tabindex="-1" value="点点点点点" id="btn"> <input type="text" placeholder="1"> <input type="text" placeholder="2"> <input type="text" placeholder="3" id="jj"> <input type="text" placeholder="4"> <input type="text" placeholder="5"> <input type="text" placeholder="6"> </div> <script type="text/javascript" src="jquery-1.11.3.min.js" ></script> <script> $(function () { var a = document.querySelector("#jj"); a.nextSibling.focus(); // a.nextElementSibling.focus(); }) </script> </body>
控制台报错,:22 Uncaught TypeError: a.nextSibling.focus is not a function 。查资料,原因可能是nextSibling获取的是文本节点或注释节点。改用nextElementSibling.focus()就正常了。
最新文章
- redis成长之路——(六)
- 工作中遇到的一个多线程下导致RCW无法释放的问题
- function,new function,Function,new Function 之间的区别
- Flash插件地址
- Homebrew OS X 不可或缺的套件管理器
- jqChart动态数据
- Spring、控制反转与依赖注入(概念)
- discuz开发学习
- eclipse中console的输出行数控制
- 【Java】java 中的泛型通配符——从“偷偷地”地改变集合元素说起
- Android基础_web通信3
- Servlet生命周期与工作原理(转载)
- Windows2008+MyEclipse10+Android开发环境搭配
- react生命周期-新增与替换
- vue-router+elelment-ui,实现导航栏激活高亮
- 【Spring】22、Spring缓存注解@Cache使用
- 一个判断男女性别的JS脚本
- A*与IDA*
- Android sdk content loader 0%
- C#学习笔记(九):函数、代码查询和调试