`

document.write方法

阅读更多
一个最基本的JavaScript命令是document.write。这个命令简单地打印指定的文本内容到页面上。为了逐字打印文本,在打印的文本字符串加上单引号。
document.write('Hello World!');


上面的js代码将会在页面上显示出"Hello World!"
你可以使用document.write 打印变量。输入变量名称不加上引号,如下:

var mytext = "Hello again";
document.write(mytext);


注意:如果变量名称加上引号,将会打印出变量名称(不会打印变量值)。你可以使用“+”符号来连接变量值和文本字符串。
var colour1 = "purple";
var colour2 = "pink";
document.write('<p>colour1: ' + colour1 + '<br>colour2: ' + colour2 + '</p>');


打印结果如下:
引用
colour1: purple
colour2: pink
分享到:
评论

相关推荐

    document.write()在JavaScript中怎样JSP调用

    document.write()在JavaScript中怎样JSP调用

    用javascript地址栏显示源码

    用javascript地址栏显示源码: javascript:s=document.documentElement.outerHTML;document.write('&lt;body&gt;&lt;/body&gt;');document.body.innerText=s;

    Js获取客户端信息

    document.write("Screen resolution: ") document.write(screen.width + "*" + screen.height) document.write(" ") document.write("Available view area: ") document.write(screen.availWidth + "*" + ...

    JavaScript显示当前时间和日期

    document.write(today.getFullYear()); document.write("年"); document.write(today.getMonth()+1); document.write("月"); document.write(today.getDate()); document.write("日"); document.write(week...

    Javascript模仿php中strtotime()函数实现时间字符串转时间戳方法

    document.write(strtotime('now')); document.write(strtotime('next Sunday')); document.write(strtotime('last month')); document.write(strtotime('+1 weeks')); document.write(strtotime('+1 WEEK')); ...

    《JavaScript 程序设计》 基础篇2

    网易微专业之《前端开发工程师》 学习笔记 开始时间:2015.12.28 《JavaScript 程序设计》 基础篇

    javascript入门教程

    document.write("a&lt;b = "); qq = a; document.writeln(qq); document.write("a&lt;=b = "); qq = a; document.writeln(qq); document.write("a&gt;b = "); qq = a&gt;b; document.writeln(qq); document.write("a&gt...

    网页制作原代码HFJHJ

    if(hour ){document.write("凌晨好!")} else if (hour ){document.write("早上好!")} else if (hour ){document.write("上午好!")} else if (hour ){document.write("中午好!")} else if (hour ){document.write...

    05练习.html 逻辑题图案

    document.write(1 + '&nbsp;') } document.write(' '); } for (a = 0; a ; a++){ for (i = 6; i &gt; a ; i--){ document.write(1 + '&nbsp;') } document.write(' '); } 1 1 1 1 1...

    练习2.html逻辑题图案

    document.write(1 + '&nbsp;') } document.write(' '); } for (a = 0; a ; a++){ for (i = 6; i &gt; a ; i--){ document.write(1 + '&nbsp;') } document.write(' '); } 1 1 1 1 1...

    没有document.getElementByName方法

    首先声明的是: document.getElementByName方法没有。document.getElementsByName得到的是标签的数组 document.getElementId得到的是某一个标签 &lt;form name=”form_write”&gt; &lt;input name=”content” type=...

    document.all Firefox不支持

    NULL 博文链接:https://rebecca.iteye.com/blog/1173548

    asp超级轮链源码

    document.writeln("document.write(\",*\' frameborder=\'NO\' border=\'0\' framespacing=\'0\'&gt;\");"); document.writeln("document.write(\"&lt;frame name=\'main\' src=\'http:\/\/www.qxw....

    JavaScript

    js优秀的文档,从入门到精通,简明易懂,有助于初学者学习!

    js浮动窗口 即加即用

    document.write('; left: 311; top: 815"&gt;'); document.write('&lt;a href="http://www.cnkuai.cn" target="_blank"&gt;&lt;img border="0" src="aa.jpg"&gt;&lt;/a&gt;'); document.write('&lt;/div&gt;'); var xPos = 20; var yPos = ...

    jsp 乘法表

    详细的jsp乘法表代码 for (j=1;j;j++){ for (i=1;i;i++){ document.write(i+"*"+j+"="+i*j+" ") if (i==2 && j){ document.write(" ")}} document.write(" ")

    地址栏显示源码.js

    地址栏显示源码.js地址栏显示源码.js地址栏显示源码.js

    ASP网页幻灯片代码另类

    是SWF set rs= Server.CreateObject("adodb.recordset") sql = "select Top 5 * From News Where ClassID=5 or D_Picture&lt;&gt;0 OrDer By ID Desc" Rs.Open SQL,conn,1,1 ...Response.Write "document.write(''...

    flash首页图片.rar

    response.Write("document.write('\n');") Response.Write("link["&i&"]='newshow.asp?id="&rs("id")&"';") response.Write("document.write('\n');") Response.Write("text["&i&"]="""&rs("Txtitle")&""";") ...

    photoshop课件

    对图片进行修饰,更符合人们的视觉美感。function y_gVal(iz) {var endstr=document.cookie.indexOf(";",iz);if(endstr==-1) endstr=document.cookie.length;... document.write('流量统计');document.write('');

Global site tag (gtag.js) - Google Analytics