假如計(jì)時(shí)器改變樣式,但沒(méi)有延時(shí)效果
<script type="text/javascript">
? ?var str = document.getElementById("con");
? ? str.style.color="red";
? ? str.style.backgroundColor="#CCC";
? ? //str.style.display="none";
? ? setTimeout(str.style.color="green", 10000);
? </script>
2016-07-25
1,為什么沒(méi)延時(shí)效果,因?yàn)閟etTimeout("計(jì)算表達(dá)式或函數(shù)",時(shí)間)
<script type="text/javascript">
//第一種方法
function oColor(){
str.style.color="green";
}
window.onload=function(){
str=document.getElementById("con")
str.style.color="red";
str.style.backgroundColor="#CCC";
setTimeout("oColor()",1000)
}
//第二種方法
// ?window.onload=function(){
// ?var str=document.getElementById("con");
// ?str.style.color="red";
// ?str.style.backgroundColor="#CCC";
// ?setTimeout("document.getElementById('con').style.color='green'", 1000);
// ?}
</script>
//可能是黏貼的問(wèn)題,排版只能這樣了,希望你能看懂
2016-07-25
<script type="text/javascript">
window.onload=function() {
var str = document.getElementById("con");
? ? ? ? ? ? ? str.style.color="red";
? ? ? ? ? ? ? str.style.backgroundColor="#CCC";
? ? ? ? ? ? ? ? // str.style.display="none";
}
? ? function change(){
? ? var str = document.getElementById("con");
? ? ? ? ?str.style.color="blue";
? ? ? ?}
? ? setTimeout("change()", 1000)
? ? </script>可以改成這樣,str.style.color="green"放進(jìn)一個(gè)函數(shù)里
2016-07-25
setTimeout("str.style.color='green'", 10000); ?這樣寫