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

如何处理document.write("<script>.....<\/script>")这样的语句
代码如下
<script>
document.write( " <script> ");
document.write( "cnxad_url= 'http://x.cnxad.com ' ");
document.write( "cnxad_f=click_normal ");
document.write( "cnxad_userid= '10523 ' ");
document.write( "cnxad_logo= 'true ' ");
document.write( "cnxad_encode=%2fZ%2bGxLBUONs4F9UkMrZy8j6ytrNvq8JEn4LgTbAXbUo%3d&et=1 ");
document.write( "cnxad_width= '300 ' ");
document.write( "cnxad_height= '300 ' ");
document.write( "cnxad_title=document.title ");
document.write( " <\/script> <script  
src= 'http://x.cnxad.com/code.js '> <\/script> ");
</script>

程序运行后报错   : 'cnxad_userid '未定义

------解决方案--------------------
<script>
document.write( " <script> ");
document.write( "cnxad_url= 'http://x.cnxad.com '; ");
document.write( "click_normal= 'http://x.cnxad.com '; ");
document.write( "cnxad_f=click_normal; ");
document.write( "cnxad_userid= '10523 '; ");
document.write( "cnxad_logo= 'true '; ");
document.write( "cnxad_encode= '%2fZ%2bGxLBUONs4F9UkMrZy8j6ytrNvq8JEn4LgTbAXbUo%3d&et=1 '; ");
document.write( "cnxad_width= '300 '; ");
document.write( "cnxad_height= '300 '; ");
document.write( "cnxad_title=document.title; ");
document.write( " </sc ", "ript> <script src= 'http://x.cnxad.com/code.js '> <\/script> ");
</script>
------解决方案--------------------
</script> 标签写法没错,cnxad_userid未定义是因为你的click_normal在代码里未定义。进而导至下边的代码也出错了,而且你应当在每一行都加上;语句结束符,因为document.write后的代码是不自动换行的,其实document.write后的代码都连一块上了。