<html>
<script type="text/javascript">
var str="a";
function fun(){
str="abcd";
}
</script>
<body onload="fun();">
<script type="text/javascript">
document.write(str);
</script>
</body>
</html>
我想让str输出为abcd,不知道什么原因总是输出a,怎么让str显示出abcd?
<script type="text/javascript">
var str="a";
function fun(){
str="abcd";
}
</script>
<body onload="fun();">
<script type="text/javascript">
document.write(str);
</script>
</body>
</html>
我想让str输出为abcd,不知道什么原因总是输出a,怎么让str显示出abcd?
<script type="text/javascript">
var str="a";
function fun(){
str="abcd";
document.write(str);
}
</script>
<body onload="fun();">
</body>
</html>
<script type="text/javascript">
document.write(str);
</script>
<html>
<script type="text/javascript">
var str="a";
function fun(){
str="abcd";
document.write(str);
}
</script>
</body>
</html>ONLOAD多此一举
str="abcd";
function fun(){ 去掉不就行了...如果你是想onload="fun();"加载的话你就输出一下!
添加document.write(str);
<script type="text/javascript">
var str="a";
str="abcd";
document.write(str);
</script>
</body>
</html>
写错了
<html>
<script type="text/javascript">
var str="a";
function fun(){
str="abcd";
}
</script>
<body onload="fun();">
<script type="text/javascript">
fun();
document.write(str);
</script>
</body>
</html>
onload是页面显示完后才执行的,你document.write(str);的时候,onload的方法还没有执行呢。
<html>
<script type="text/javascript">
var str="a";
function fun(){
str="abcd";
}
fun();
</script>
<body>
<script type="text/javascript">
document.write(str);
</script>
</body>
</html>