假如計時器改變樣式,但沒有延時效果
<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,為什么沒延時效果,因為setTimeout("計算表達式或函數(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>
//可能是黏貼的問題,排版只能這樣了,希望你能看懂
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"放進一個函數(shù)里
2016-07-25
setTimeout("str.style.color='green'", 10000); ?這樣寫