用javascript更改图像src不起作用
change image src with javascript not working
这是我的代码
function playPause(){
movie = document.getElementById('movieEMBED');
icon = document.getElementById('playPauseIcon');
var isPlaying;
isPlaying = movie.GetRate();
if (!isPlaying){
movie.Play();
icon.setAttribute('src', "images/pausebutton.png");
}
else {
movie.Stop();
icon.setAttribute('src', "images/playbutton.png");
}
}
在html:中
<input type="image" id="playPauseIcon" src="images/playbutton.png" width=30px onClick='playPause()'></input>
有什么想法吗?为什么当我点击按钮时,图片没有在暂停和播放按钮之间切换?
我猜是因为你的电影正在播放。if块的else
将src设置为相同的值:
if (!isPlaying){
movie.Play();
icon.setAttribute('src', "images/pausebutton.png");
}
else {
movie.Stop();
icon.setAttribute('src', "images/playbutton.png"); // <---- no change
}
为了确保你的代码是正确的,我会把函数改为:
function playPause(){
var icon = document.getElementById('playPauseIcon');
icon.setAttribute('src', "images/pausebutton.png");
}
然后慢慢添加您的电影代码
据我所见,您的代码很好。你确定是电影吗。GetRate()返回不同的值,您是否正确地通过了"if"的两个路径?我想看电影。GetRate()总是返回相同的值,因此您永远不会将src属性设置为不同的图像。
相关文章:
- jQuery place attr src在Chrome中不起作用
- setAttribute和video.src用于更改IE9中不起作用的视频标记源
- 如果iframe在src(pdf或text)中有非html文档,则iframe中的onload不起作用
- 相对网址在JavaScript(element.src)中不起作用
- AngularJs ng-include src =“sample.html ” 不起作用
- 保存图像 src 的功能不起作用
- 在图像不起作用的 src 中添加 jQuery 变量
- AngularJS - img ng-src 到 base64 数据(不是 url)不起作用
- 设置图像 SRC 在火狐浏览器上不起作用
- 脚本 SRC 归因有时在.php文件中不起作用
- 奇怪的 img src 路径,在本地主机上不起作用
- 脚本标签的动态创建和 src 加载在 ie10 中不起作用
- document.getElementById('foo').src='' 不起作用
- Javascript set src 属性的图像不起作用
- href 中的角绑定有效,但 src 绑定不起作用
- 改变iframe src的Javascript;不起作用
- 用javascript更改图像src不起作用
- jQuery更新图像src不起作用
- Javascript:更改src不起作用
- 更改iframe的src不起作用