关于document.write和document.writeln的真正区别 一般的解释是document.writeln会在字符串后面添加一个换行符(\n)为什么我测试页面时发现2者是一样的效果呢,document.writeln也没有给字符串后面添加换行符(\n)... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 document.write()和document.writeln都是JavaScript向客户端写入的方法writeln是以行方式输出的,一般情况下用两种方法输出的效果在页面上是没有区别的,两种方法仅当在查看源代码时才看得出区别,除非是输出到pre或xmp元素内测试一下:<script> with(window.open()){ document.write("百度")document.write("百度")document.writeln("知道")document.writeln("知道")document.writeln("知道")} </script>运行上面的代码,在新开的窗口中:查看-源文件,就可以看到,writeln是以行方式输出关于保留格式,测试一下:<script> document.write("<pre>百度")document.write("百度")document.writeln("知道")document.writeln("知道")document.writeln("知道</pre>") </script> 你可能是用的inner.html用inner.text试试 document.writeln("aaa");document.write("aaa\n");这两个等价至于为什么没换行,在html中换行符号是<br>,\n是字符串的换行符 上面都说了。我再蹭点分<script> document.writeln("<textarea>百度")document.writeln("百度")document.write("知道1")document.writeln("知道2")document.write("知道</textarea>") </script> zswang说了:哥缺的不是分,个缺的是寂寞 js代码可以关掉手机浏览器 'style' 为空或不是对象 大侠来救我,扫盲扫盲扫盲... JS能否使用?来传递动态变化的参数,若不行,有无其他办法实现 javascript 属性的方法如何访问其所在对象的其它属性或方法???? js文件不能被调用的问题,急! 散分请教基础问题:如何用JS让一个图片有一般的机率显示? 怎样将列表框中选中的项通过点击按钮添加到另一个列表框中? 如何读取列表框可以多选后的值? 请教用javascript实现计算同名checkbox控件的数目(急!!!) jquery取值问题 使用过dtree的大哥们帮我看下问题
document.write()和document.writeln都是JavaScript向客户端写入的方法writeln是以行方式输出的,一般情况下用两种方法输出的效果在页面上是没有区别的,两种方法仅当在查看源代码时才看得出区别,除非是输出到pre或xmp元素内测试一下:<script>
with(window.open()){
document.write("百度")
document.write("百度")
document.writeln("知道")
document.writeln("知道")
document.writeln("知道")
}
</script>运行上面的代码,在新开的窗口中:查看-源文件,就可以看到,writeln是以行方式输出关于保留格式,测试一下:<script>
document.write("<pre>百度")
document.write("百度")
document.writeln("知道")
document.writeln("知道")
document.writeln("知道</pre>")
</script>
用inner.text试试
document.write("aaa\n");
这两个等价
至于为什么没换行,在html中换行符号是<br>,\n是字符串的换行符
document.writeln("<textarea>百度")
document.writeln("百度")
document.write("知道1")
document.writeln("知道2")
document.write("知道</textarea>")
</script>