日期:2014-05-16  浏览次数:20273 次

关于javascript中document.write的写法。。。。大家帮一下忙
各位javascript中document.write怎么好像有好多的写法啊。。。到底有哪几种,我目前知道的只有
document.write('\
<style>\
.sinafoot *{ margin:0px; padding:0px; }\
.sinafoot{ width:90%; margin:20px auto 10px; text-align:center; font-size:12px; clear:both }\
.sinafoot a:link{ color:#001A9F;TEXT-DECORATION: none}\
.sinafoot a:visited{ color:#001A9F;TEXT-DECORATION: none}\
.sinafoot a:hover{ color:#BD0302;TEXT-DECORATION: underline; }\
.sinafoot p{ height:24px; clear:both; color:#525252;}\
</style>\
<div class="sinafoot">\
<p><a href="http://control.video.sina.com.cn/useradmin/advice/advice_list.html" target="_blank">新浪互联星空播客意见反馈留言板</a>\ 电话:95105670 提示音后按2键(按当地市话标准计费) 欢迎批评指正</p>\
<p>\
<a href="http://corp.sina.com.cn/chn/" target="_blank">新浪简介</a> | \
<a href="http://corp.sina.com.cn/eng/" target="_blank">About Sina</a> | \
<p>新浪公司 <a href="http://www.sina.com.cn/intro/copyright.shtml" target="_blank">版权所有</a></p>\
</div>\
');


document.write("<div style=\"display:none\"><img id=\"WRServerImg\" width=\"1\" height=\"1\" /></div>");
这两种写法为什么有的在引号前面加斜线而有的则加单引号呢

------解决方案--------------------
看要输出 <.. xx="" > 还是 <.. xx='' >
字符串""中双引号用\"转义,以和字符串的结束符号"区别。
单引号也可以用\'转义。
------解决方案--------------------
其实,完全可以将write里面的" 改为 '
------解决方案--------------------
就一种写法。
------解决方案--------------------
js里"和'通用,都表示字符串常量。但是必须间隔开来用
比如"后用'就不需要斜杠(\)来转意。但是用"就必须,否则解析器以为你在结束前一个"
------解决方案--------------------
关注 接分