0

我正在使用 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();

4

1 回答 1

1
document.images["sound"].src = "/img/soundOff.png";

应该是这样的:

document.getElementById('your_id').src = "/img/soundOff.png";

你的路径对我来说似乎有点奇怪。正确检查

于 2013-09-17T18:40:08.943 回答