首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

关于innerText简单有关问题?

2012-02-27 
关于innerText简单问题???????????htmlheadfunctionf(){document.body.innerText +indexindex++

关于innerText简单问题???????????
<html>
    <head>
function   f(){
   
    document.body.innerText= " "+index;
    index++;
window.setTimeout( "f() ",1000);
}
</script>
    </head>
   
    <body   onload= "f() ">
        <div   id= "grant "> </div>
    </body>
</html>

为什么document.body.innerText= " "+index;就可以有输出
但换成document.grant.innerText= " "+index;没有输出了
这是为什么啊?????????

[解决办法]
document.grant.innerText//没这种写法
==>
document.getElementById( "grant ").innerText
[解决办法]
<html>
<head>
<script type= "text/javascript ">
function f(){

document.getElementById( "grant ").innerText=index;
index++;
window.setTimeout( "f() ",1000);
}
</script>
</head>

<body onload= "f() ">
<div id= "grant "> </div>
</body>
</html>


[解决办法]
document.getElementById( "grant ")

or

window.grant
[解决办法]
好像对DIV,不能用document+DIVID,要不就直接用grant.innerText,或document.getElementByID( "grand ").innerText

热点排行