我正在使用 jquery mobile 制作应用程序。当页面加载并显示图像以在单击时关闭声音文件时,我正在播放声音文件。一切正常,但是我只能在索引页面上更改图像。我可以关闭任何页面上的声音文件,但图像不会在任何其他页面上改变。请帮助=) <3
<script type="text/javascript">
var newsrc = "soundOff.png";
function changeImage() {
var sample = document.getElementById("foobar");
sample.pause();
if ( newsrc == "soundOff.png" ) {
document.images["sound"].src = "/img/soundOff.png";
document.images["sound"].alt = "Sound Off";
newsrc = "soundOn.png";
}
else {
var sample = document.getElementById("foobar");
sample.play();
document.images["sound"].src = "/img/soundOn.png";
document.images["sound"].alt = "Sound On";
newsrc = "soundOff.png";
}
}
var sample = document.getElementById("foobar");
sample.play();