gpt4 book ai didi

javascript - 我收到错误类型错误 : Cannot read property 'addEventListener' of null

转载 作者:行者123 更新时间:2023-11-30 20:51:08 24 4
gpt4 key购买 nike

<分区>

我有以下代码片段,我不确定为什么事件监听器不工作。它给出错误:Uncaught TypeError: Cannot read property 'addEventListener' of null

var btn = document.getElementById("button");

var priceshow = document.querySelector("#price");

btn.addEventListener("click", function(){
var XHR = new XMLHttpRequest();

XHR.onreadystatechange = function() {
if (XHR.readyState == 4 && XHR.status == 200) {
var data = JSON.parse(XHR.responseText);
var price = data.bpi.GBP.rate;
priceshow.innerText = price;
}
}

var url = "https://api.coindesk.com/v1/bpi/currentprice.json";
XHR.open("GET", url);
XHR.send();
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com