输出内容(document.write)

时间:2023-03-08 22:46:33
输出内容(document.write)

document.write() 直接在页面中输出内容

第一种 直接输出

document.write("I Love Javascript !") //输出内容为:I Love Javascript !

第二种 通过变量输出

var mystr = "hallo world!";

document.write(mystr); //输出结果为:hallo world!

第三种 输出多项内容,内容之间用+号链接

var mystr = "hello";

document.write(mystr+"I Love Javascript"); //输出内容为:hello I Love Javacsript

第四种 输出HTML标签,标签使用""括起来

var mystr = "hello";

document.write(mystr+"<br>");  //输出的内容会换行

document.write("javascript");