Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法读取null的属性样式?_Javascript_Transitions - Fatal编程技术网

Javascript 无法读取null的属性样式?

Javascript 无法读取null的属性样式?,javascript,transitions,Javascript,Transitions,我是一个javascript新手,我正在尝试编写一个脚本来实现柔和的颜色更改,但是当调用要更改的对象时,我遇到了一些问题。我的代码是: <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 =

我是一个javascript新手,我正在尝试编写一个脚本来实现柔和的颜色更改,但是当调用要更改的对象时,我遇到了一些问题。我的代码是:

<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()
我的h1是:

<h1 align="center" id="title">Degradando...</h1> 
degrandado。。。
我注意到id写入正确,那么,问题出在哪里?

尝试执行以下操作:

window.onload = function(){
  document.getElementById("title").style.color
}

我认为您甚至在创建元素之前就已经在访问它了。

onload
处理程序调用您的函数:

window.onload = function() {
    degradado();
}

因此,它将在加载DOM后运行。

确保您的Javascript在加载DOM元素后运行。好的,谢谢,它确实解决了问题,但它不起作用,它以前使用过bgcolor。你能注意到我的错误吗?
window.onload = function() {
    degradado();
}