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 得不到继承对象的属性 一个问题,很困惑。 求一本书的源代码,希望大家可以帮我找到。 求助!!!为什么radio的onclick事件无效啊???? 帮帮我呀,学生做项目中。。。 一个窗口弹出问题--附脚本(急求解答)! 完美控制aspx页面显示图片的大小 我有个id="A1.EndDate"的textbox 在客户端怎么用js访问她啊?这样子写不行,点击没有反映 如何创建一个自定义的对象,此对象的属性里含有另一自定义对象? 在这种情况下,如何得到text的value? 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