“document.getElementByClass不是函数” [英] "document.getElementByClass is not a function"

查看:3141
本文介绍了“document.getElementByClass不是函数”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 class =stopMusic运行onClick任何按钮的函数。我在Firebug中收到错误

I am trying to run a function onClick of any button with class="stopMusic". I'm getting an error in Firebug


document.getElementByClass不是函数

document.getElementByClass is not a function

这是我的代码:

var stopMusicExt = document.getElementByClass("stopButton");
    stopButton.onclick = function() {
        var ta = document.getElementByClass("stopButton");
        document['player'].stopMusicExt(ta.value);
        ta.value = "";
    };


推荐答案

您可能需要文件。 getElementsByClassName()(然后从结果节点列表中抓取第一个项目):

You probably meant document.getElementsByClassName() (and then grabbing the first item off the resulting node list):

var stopMusicExt = document.getElementsByClassName("stopButton")[0];

stopButton.onclick = function() {
    var ta = document.getElementsByClassName("stopButton")[0];
    document['player'].stopMusicExt(ta.value);
    ta.value = "";
};

您可能仍会收到错误


document.getElementsByClassName 不是函数

但是,在旧版浏览器中,如果您需要支持这些旧浏览器,则可以提供回退实现。

in older browsers, though, in which case you can provide a fallback implementation if you need to support those older browsers.

这篇关于“document.getElementByClass不是函数”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆