我是javascript中的新手,我正在尝试做一个脚本来进行软颜色的更改,b但是当调用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是正确写的,那么,有什么问题吗?
发布于 2014-04-10 02:19:50
试着这样做:
window.onload = function(){
document.getElementById("title").style.color
}我认为您甚至在创建元素之前就访问了它。
发布于 2014-04-10 02:34:07
从onload处理程序调用您的函数:
window.onload = function() {
degradado();
}以便在加载DOM之后运行。
https://stackoverflow.com/questions/22977501
复制相似问题