我有一个 js 脚本,它正在提取类的内文本。有时该类未在网页上呈现,因此在这种情况下,内文本未定义。我想对此进行检查,以便忽略此错误。这是我编写的代码 ->function myfunc() {var button = document.getElementsByClassName('myclass');if (button[0].innerText !== undefined) {console
2021-11-09
html:<!DOCTYPE html><html><head><script src="plm.js"></script></head><body><h1 id="element">number</h1><button onclick="bruh()">Add Num</button></body></html>jslet nr = 0let change = document.getEleme
2022-08-23
错误是:Cannot read properties of undefined (reading 'innerText')当我尝试运行代码时出现此错误。var addCart = document.getElementsByClassName("add-cart");for (var i = 0; i < addCart.length; i++) {var button = addCart[i];
2022-12-21