我一直在学校网站上工作,出于某种原因,当我尝试更改控制台输出的源链接时Uncaught TypeError: Cannot set property 'href' of null at pierre (pierre.html:49) at HTMLButtonElement.onclick (pierre.html:60)我试图通过更改 ID 来解决此问题,但它也不起作用,即使将“link1”行复制并粘贴到“link2”行上也不起作用。<!DOCTYPE html><html> <head> <meta charset="utf-8"> <meta content="pierre, omidyar, bourne"> <title id="title">Pierre Omidyar</title> </head><script> var x = 0; function pierre() { if (x == 0) { x = 1 document.getElementById('title').innerHTML='Pierre\xa0Bourne'; document.getElementById('heading').innerHTML='Pierre\xa0Bourne'; document.getElementById('tag').play(); document.getElementById('image1').src='https://cdn3.pitchfork.com/longform/699/Pierre1.jpg'; document.getElementById('cite1').innerHTML = "Sheldon Pearce, Pitchfork.com, 2019"; document.getElementById('para1').innerHTML = "Jordan Timothy Jenks, known professionally as Pi\'erre Bourne, is a Belizean-American record producer, rapper, songwriter, and audio engineer. He is known for producing the singles \"Magnolia\" by Playboi Carti, and \"Gummo\" by 6ix9ine, with the two peaking at number 29 and 12 on the US Billboard Hot 100 respectively."; document.getElementById('link1').href = "https://en.wikipedia.org/wiki/Pierre_Bourne"; document.getElementById('image2').src='https://cdn3.pitchfork.com/longform/699/Pierre4.jpg'; document.getElementById('para2').innerHTML = "Songs Pierre Bourne has produced"; document.getElementById('l1o1').innerHTML = "Magnolia"; document.getElementById('l1o2').innerHTML = "wokeuplikethis*"; document.getElementById('l1o3').innerHTML = "Pissy Pamper"; document.getElementById('l1o4').innerHTML = "Pain 1993"; document.getElementById('link2').href = "https://en.wikipedia.org/wiki/Pierre_Bourne";
1 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
看起来问题是信息的开始和结束 span/p 标签不匹配para。
具有不匹配的开始和结束标记的 HTML 会导致 javascript DOM 解析器丢失元素,尽管它们实际上位于页面上。
添加回答
举报
0/150
提交
取消
