解决方案 »

  1.   

    <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>
      

  2.   


    我是这样做的,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 这是为什么。。
      

  3.   

    楼上正解
    如果用jquery:
    $("#txt").get(0).tagName.toLowerCase()
      

  4.   


    我是这样做的,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
      

  5.   

    是返回有的为空,有的不为空,为空的没tagName属性,没有判断是否为空就拿去读tagName,所以控制台报错。
    多谢楼上两位@u013472677    @jikeytang