[英]Using javascript to change an icon-font for a media player?
I am trying to develop a very minimal audio player with just a play/pause button and a mute/unmute button. 我正在尝试开发一个只有播放/暂停按钮和静音/取消静音按钮的最小音频播放器。
I want to use Font-Awesome to display icons for play/pause and mute/unmute. 我想使用“超赞字体”来显示播放/暂停和静音/取消静音的图标。
I have created a fiddle where I have put my code. 我创建了一个小提琴,在其中放置了代码。 http://jsfiddle.net/EsC6L/
http://jsfiddle.net/EsC6L/
I am getting an error "Uncaught SyntaxError: Unexpected Identifier" 我收到一个错误“未捕获的SyntaxError:意外的标识符”
The console is identifying the syntax in the innerHTML as incorrect. 控制台将innerHTML中的语法标识为不正确。
btnPlayPause.addEventListener("click", function() {
if (myAudio.paused) {
myAudio.play();
btnPlayPause.innerHTML = "<i class="icon-pause"></i>";
}
else {
myAudio.pause();
btnPlayPause.innerHTML = "<i class="icon-play"></i>";
}
});
btnPlayPause is deined as a var, as is myAudio. btnPlayPause和myAudio都定义为var。
on the HTML side, I have the following 在HTML方面,我有以下内容
<div class="controls">
<button id="btnPlayPause">Play</button>
<button id="btnMute">Mute</button>
</div><!-- /controls -->
I am stumped as to how to solve this. 我为如何解决这个问题而感到困惑。
String needs escaping: 字符串需要转义:
btnPlayPause.innerHTML = "<i class=\"icon-pause\"></i>";
Demo: http://jsfiddle.net/EsC6L/2/ 演示: http : //jsfiddle.net/EsC6L/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.