Javascript使用document.write输出内容实例页面
这段命令将文本输出到页面这个例子使用Javascript的document.write命令输出指定文本的页。代码如下:
复制代码代码如下所示:
document.write(我的网页文本!;
Save the upper part of the code with a text editor as write.html (or write.htm).Double click write.html to run it (actually open this file with IE and other browsers), and you'll see that the page displays the following text:
复制代码如下:我是输出到页面的文本!
提示
如果您使用IE浏览器提示,为了保护安全性,Internet Explorer已限制Web页面的操作,以访问计算机的脚本或ActiveX空间。然后,选择允许停止的内容,以便IE浏览器运行上面的Javascript代码。
document.write输出文本和HTML标签页
如果输出到页面的文本带有HTML标记,则只能将输出文本中的文本带到标签中。
复制代码代码如下所示:
document.write(我的网页文本!;
格语法解释
类似于Javascript弹出提示框前面的例子,段是标准的Javascript语法的命令,这是用来输出字符串的网页。特点是输出引用或放在document.write()。
这段命令,本例中使用的指令弹出警报将在未来的Javascript学习经常使用的,一定要巧妙地使用它。