JavaScript-輸出內(nèi)容(document.write)
document.write()可用于直接向 HTML 輸出流寫內(nèi)容盯腌。簡(jiǎn)單的說就是直接在網(wǎng)頁中輸出內(nèi)容。
第一種:輸出內(nèi)容用""括起息裸,直接輸出""號(hào)內(nèi)的內(nèi)容辜限。
<script type = "text/javascript">
document.write("I like javaScript");//輸出內(nèi)容
</script>
? document.write("I love JavaScript!");//內(nèi)容用""括起來焦影,""里的內(nèi)容直接輸出宣增。
第二種:通過變量玫膀,輸出內(nèi)容
<script type = "text/javascript">
var str = "hello world!";
document.write(str);//輸出內(nèi)容
</script>
? var mystr="hello world!";? document.write(mystr); //直接寫變量名,輸出變量存儲(chǔ)的內(nèi)容爹脾。
第三種:輸出多項(xiàng)內(nèi)容帖旨,內(nèi)容之間用+號(hào)連接。
<script type = "text/javascript">
var str = "hello world!";
document.write(str+"I'm javaScript");//輸出內(nèi)容
</script>
? var mystr="hello";? document.write(mystr+"I love JavaScript");//多項(xiàng)內(nèi)容之間用+號(hào)連接
第四種:輸出HTML標(biāo)簽灵妨,并起作用解阅,標(biāo)簽使用""括起來。
<script type = "text/javascript">
var str = "hello world!";
document.write(str+"<br>"+"I'm javaScript");//輸出內(nèi)容
</script>
? var mystr="hello";document.write(mystr+"
");//輸出hello后泌霍,輸出一個(gè)換行符document.write("JavaScript");