Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to run a function onclick of any button with class="stopMusic" .(我正在尝试使用class="stopMusic"对任何按钮运行onclick函数。)

I'm getting an error in Firebug(我在Firebug中遇到错误) document.getElementByClass is not a function(document.getElementByClass不是函数) Here is my code:(这是我的代码:) var stopMusicExt = document.getElementByClass("stopButton"); stopButton.onclick = function() { var ta = document.getElementByClass("stopButton"); document['player'].stopMusicExt(ta.value); ta.value = ""; };   ask by user547794 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
366 views
Welcome To Ask or Share your Answers For Others

1 Answer

You probably meant document.getElementsByClassName() (and then grabbing the first item off the resulting node list):(您可能是指document.getElementsByClassName() (然后从结果节点列表中获取第一项):)

var stopMusicExt = document.getElementsByClassName("stopButton")[0]; stopButton.onclick = function() { var ta = document.getElementsByClassName("stopButton")[0]; document['player'].stopMusicExt(ta.value); ta.value = ""; }; You may still get the error(您可能仍然会收到错误) document.getElementsByClassName is not a function(document.getElementsByClassName不是函数) in older browsers, though, in which case you can provide a fallback implementation if you need to support those older browsers.(但是,在较旧的浏览器中,如果需要支持那些较旧的浏览器,则可以提供后备实现。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
...