Javascript-在一段时间后更改图像
这可能是一个常见的问题,但我已经尝试了一些解决方案,我的代码还不能工作 所以,我的WYSIWYG页面上有一个.GIF图像。通过将ImageStart.jpg更改为My Image.gif,我的代码可以很好地启动和重播My.gif。但我需要在image.gif结束后加载一个新图像“ImageEnd.jpg” 因此,我尝试设置超时:Javascript-在一段时间后更改图像,javascript,image,wysiwyg,Javascript,Image,Wysiwyg,这可能是一个常见的问题,但我已经尝试了一些解决方案,我的代码还不能工作 所以,我的WYSIWYG页面上有一个.GIF图像。通过将ImageStart.jpg更改为My Image.gif,我的代码可以很好地启动和重播My.gif。但我需要在image.gif结束后加载一个新图像“ImageEnd.jpg” 因此,我尝试设置超时: function play(){ if (document.getElementById("Pesquisa").src = "http://www.lyuz.co
function play(){
if (document.getElementById("Pesquisa").src = "http://www.lyuz.com.br/media/./images/Software/PesquisaStart.jpg"){
document.getElementById("Pesquisa").src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa.gif";
}else{
document.getElementById("Pesquisa").src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa1.gif";
}
SetTimeout(function(){end()},24000);
}
function end(){
document.getElementById("Pesquisa").src = "http://www.lyuz.com.br/media/./images/Software/PesquisaEnd.jpg";
}
在我看来,我的代码应该在24秒后将my Image.gif更改为ImageEnd.jpg,这是动画的长度
有什么问题吗?如果
条件中的逻辑有问题,除了设置超时
拼写错误之外。应该使用两个等号来执行比较。另外,尝试存储对DOM元素的引用,而不是每次都搜索它。这也有助于代码更干净
function play(){
var img = document.getElementById("Pesquisa");
if (img.src == "http://www.lyuz.com.br/media/./images/Software/PesquisaStart.jpg"){
img.src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa.gif";
}else{
img.src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa1.gif";
}
setTimeout(function(){end()},24000);//you had SetTimeout(...), upperCased S previously
}
function end(){
document.getElementById("Pesquisa").src = "http://www.lyuz.com.br/media/./images/Software/PesquisaEnd.jpg";
}
除了拼写错误之外,if
条件中的逻辑也有错误。应该使用两个等号来执行比较。此外,尝试存储对DOM元素的引用,而不是每次都搜索它。这也有助于代码更干净
function play(){
var img = document.getElementById("Pesquisa");
if (img.src == "http://www.lyuz.com.br/media/./images/Software/PesquisaStart.jpg"){
img.src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa.gif";
}else{
img.src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa1.gif";
}
setTimeout(function(){end()},24000);//you had SetTimeout(...), upperCased S previously
}
function end(){
document.getElementById("Pesquisa").src = "http://www.lyuz.com.br/media/./images/Software/PesquisaEnd.jpg";
}
除了拼写错误之外,if
条件中的逻辑也有错误。应该使用两个等号来执行比较。此外,尝试存储对DOM元素的引用,而不是每次都搜索它。这也有助于代码更干净
function play(){
var img = document.getElementById("Pesquisa");
if (img.src == "http://www.lyuz.com.br/media/./images/Software/PesquisaStart.jpg"){
img.src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa.gif";
}else{
img.src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa1.gif";
}
setTimeout(function(){end()},24000);//you had SetTimeout(...), upperCased S previously
}
function end(){
document.getElementById("Pesquisa").src = "http://www.lyuz.com.br/media/./images/Software/PesquisaEnd.jpg";
}
除了拼写错误之外,if
条件中的逻辑也有错误。应该使用两个等号来执行比较。此外,尝试存储对DOM元素的引用,而不是每次都搜索它。这也有助于代码更干净
function play(){
var img = document.getElementById("Pesquisa");
if (img.src == "http://www.lyuz.com.br/media/./images/Software/PesquisaStart.jpg"){
img.src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa.gif";
}else{
img.src = "http://www.lyuz.com.br/media/./images/Software/Pesquisa1.gif";
}
setTimeout(function(){end()},24000);//you had SetTimeout(...), upperCased S previously
}
function end(){
document.getElementById("Pesquisa").src = "http://www.lyuz.com.br/media/./images/Software/PesquisaEnd.jpg";
}
使用onload事件:
document.getElementById(“Pesquisa”).onload=function(){end()}使用onload事件:
document.getElementById(“Pesquisa”).onload=function(){end()}使用onload事件:
document.getElementById(“Pesquisa”).onload=function(){end()}使用onload事件:
document.getElementById(“Pesquisa”).onload=function(){end()}JS中没有SetTimeout
,它是SetTimeout
,JS是区分大小写的。当你有问题时,一定要检查控制台。你肯定有错误。JS中没有SetTimeout
,它是SetTimeout
,JS是区分大小写的。当你有问题时,一定要检查控制台。你肯定有错误那里有错误。JS中没有SetTimeout
,它是SetTimeout
,JS是区分大小写的。当你有问题时,一定要检查控制台。那里肯定有错误。JS中没有SetTimeout
,它是SetTimeout
,JS是区分大小写的。当你有问题时,一定要检查控制台。你确定我有一个错误。