document.getElementByName("type").value不能使用,没反应

版权声明:@CopyRight转载请注明出处 https://blog.csdn.net/LI_AINY/article/details/90030769
  1. 改一个老项目,使用的是原生的js,使用getElementByName()一直没有获取到想要的值,仔细排查发现是单词错误
    getElementById()
    getElementsByName()
    getElementsByTagName()
var x = document.getElementsByName("type").value;  //此时的x就是页面中所有name="type"所形成的一个数组
 var x = document.getElementsByName("type")[0].value;     //此时的x就是页面中第一个name=''type"的值
var x = document.getElementsByTagName("p")[2].value;       //此时的x是页面中第三个段落标签的值
 var x = document.getElementsByTagName("p").value;       //此时的x是一个数组,是有页面中所有<p></p>所组成的一个数组

猜你喜欢

转载自blog.csdn.net/LI_AINY/article/details/90030769
今日推荐