DOM操作,通过ID获取tagName DOM操作jquery 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <input name="xxx",id="xxInput">多了个逗号<!doctype html><html lang="en-US"><head> <meta charset="UTF-8"> <title></title></head><body><input name="xxx" id="xxInput"><script type="text/javascript"> var input = document.getElementById('xxInput'); alert(input.tagName.toLowerCase());</script></body></html> 我是这样做的,k[i][0]表示后台返回的和页面id类似的字符,// document.getElementById(k[i][0]).tagName.toLowerCase() == "input"chrome浏览器console.info(document.getElementById(k[i][0]).tagName.toLowerCase())控制台错误:Uncaught TypeError: Cannot read property 'tagName' of null 先前是这样写的document.getElementById(k[i][0]).nodeName.toLowerCase()控制台错误也是Uncaught TypeError: Cannot read property 'nodeName' of null 这是为什么。。 楼上正解如果用jquery:$("#txt").get(0).tagName.toLowerCase() 我是这样做的,k[i][0]表示后台返回的和页面id类似的字符,// document.getElementById(k[i][0]).tagName.toLowerCase() == "input"chrome浏览器console.info(document.getElementById(k[i][0]).tagName.toLowerCase())控制台错误:Uncaught TypeError: Cannot read property 'tagName' of null 先前是这样写的document.getElementById(k[i][0]).nodeName.toLowerCase()控制台错误也是Uncaught TypeError: Cannot read property 'nodeName' of null 这是为什么。。你这应该是没有找到对应的节点元素(document.getElementById(k[i][0])这有问题),所以,就不能读去tagName 是返回有的为空,有的不为空,为空的没tagName属性,没有判断是否为空就拿去读tagName,所以控制台报错。多谢楼上两位@u013472677 @jikeytang 求高人指点,js函数定义的问题 求一代码,点击图片后放大 js中取xml文件节点属性 怎么用javascript HTML 实现图片的拖拽和放大缩小? 请帮忙分析一下为什么打开的这么慢 一个关于复选框的问题 谁帮解释这个阶乘速算法的原理? 弹出的div被dropdownList(select)挡住了,怎么办? javascript正则表达式的的标识问题 JavaScript 中有和C中的sprintf,vsprintf一样功能的函数吗? amcharts柱状图,滚动条设置 表单验证的问题 帮小弟看看哪里错了
多了个逗号<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title></head>
<body>
<input name="xxx" id="xxInput">
<script type="text/javascript">
var input = document.getElementById('xxInput');
alert(input.tagName.toLowerCase());
</script>
</body>
</html>
我是这样做的,k[i][0]表示后台返回的和页面id类似的字符,
// document.getElementById(k[i][0]).tagName.toLowerCase() == "input"chrome浏览器console.info(document.getElementById(k[i][0]).tagName.toLowerCase())
控制台错误:Uncaught TypeError: Cannot read property 'tagName' of null
先前是这样写的document.getElementById(k[i][0]).nodeName.toLowerCase()
控制台错误也是Uncaught TypeError: Cannot read property 'nodeName' of null 这是为什么。。
如果用jquery:
$("#txt").get(0).tagName.toLowerCase()
我是这样做的,k[i][0]表示后台返回的和页面id类似的字符,
// document.getElementById(k[i][0]).tagName.toLowerCase() == "input"chrome浏览器console.info(document.getElementById(k[i][0]).tagName.toLowerCase())
控制台错误:Uncaught TypeError: Cannot read property 'tagName' of null
先前是这样写的document.getElementById(k[i][0]).nodeName.toLowerCase()
控制台错误也是Uncaught TypeError: Cannot read property 'nodeName' of null 这是为什么。。
你这应该是没有找到对应的节点元素(document.getElementById(k[i][0])这有问题),所以,就不能读去tagName
多谢楼上两位@u013472677 @jikeytang