我是javascript的新手,我试图做一个脚本来进行柔和的颜色更改,但是当调用objetc进行更改时,我遇到了一些问题。我的代码是这样的:
<script lenguage="javascript">
hexadecimal = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F")
function convierteHexadecimal(num){
var hexaDec = Math.floor(num/16)
var hexaUni = num - (hexaDec * 16)
return hexadecimal[hexaDec] + hexadecimal[hexaUni]
}
function convierteHexadecimal(num){
var hexaDec = Math.floor(num/16)
var hexaUni = num - (hexaDec * 16)
return hexadecimal[hexaDec] + hexadecimal[hexaUni]
}
color_decimal=0
function degradado(){
color_decimal ++
color_hexadecimal = convierteHexadecimal(color_decimal)
document.getElementById("title").style.color = color_hexadecimal + color_hexadecimal + color_hexadecimal
//la llamo con un retardo
if (color_decimal < 255)
setTimeout("degradado()",1)
}
degradado()
这是我的代码,但是当我将其加载到chrome中时,出现了以下问题:
document.getElementById("title").style.color
我的h1是:
<h1 align="center" id="title">Degradando...</h1>
我注意到该ID是正确写入的,那么,什么问题呢?
尝试这样做:
window.onload = function(){
document.getElementById("title").style.color
}
我认为您甚至在创建元素之前就在访问它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句