JavaScript用document.write()輸出換行的示例代碼
當(dāng)我們想用document.write()輸出換行時,可能會第一時間想到加'n',但是其實不能達(dá)到我們的想要效果,只會得到一個空格的效果。
正確的方法是使用:</br>
樣例代碼:
<!DOCTYPE html><html><head><meta charset='utf-8'><script>// 使用 n 換行 ---> 錯誤的方法document.write('這是第一句話。' + 'n'); // 并不會換行,只會得到一個空格的效果document.write('這是第二句話。');document.write('</br>'); // 正確的換行document.write('</br>');document.write('</br>');// 使用正確的方法 </br> 換行document.write('這是第一句話。。' + '</br>');document.write('這是第二句話。。');</script><title></title></head><body></body></html>
效果截圖:
到此這篇關(guān)于JavaScript用document.write()輸出換行的示例代碼的文章就介紹到這了,更多相關(guān)js document.write()輸出換行內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
