JS:getElementsByClassName()无效的原因以及解决方法

<button class="btn btn-xs btn-warning revise">编辑</button>

var revise = document.getElementsByClassName("btn btn-xs btn-warning revise")[0];

revise.οnclick=function revise() {

revBackground.style.display="block";

}

或者

var revise = document.getElementsByClassName("revise");

revise[0].οnclick=function revise() {

revBackground.style.display="block";

}

注意点:

①getElementsByClassName 中的 “Class” 是大写。

截图来源:https://zhidao.baidu.com/question/619329632613629652.html

var revise = document.getElementsByClassName("btn btn-xs btn-warning revise")[0]

var revise = document.getElementsByClassName("revise")[0]

都可以

发布了70 篇原创文章 · 获赞 23 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/tiandaochouqin_1/article/details/89150425
今日推荐