读书人

Js的话语块

发布时间: 2012-10-24 14:15:58 作者: rapoo

Js的语句块

? ? 在Js中通常没有语句块的概念。在很多语言中,语句块中定义的变量的作用范围仅限于该语句块中,不能在该语句块之外的代码使用。但是Js中,语句块中定义的变量能在其他语句块中使用。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>Js</title></head><body><script type="text/javascript">function myFun(){var i = 0;for(i = 0; i < 10; i++){var k = 1;document.writeln(i); }document.writeln(k);}myFun();</script></body></html>
? ? 注意:虽然没有语句块的限制,但是Js中函数中变量的作用还是有的。

读书人网 >JavaScript

热点推荐