首页 > Web开发 > 详细

js unterminated string constant

时间:2014-03-26 02:51:32      阅读:583      评论:0      收藏:0      [点我收藏+]

<html>
<body>
<div id="d">ddd</div>
</body>
</html>
<script>
 var url = "我们 的";
var html = "<span onclick=onMouseDown(this,‘"+url+"‘)>myspan</span>"; 
alert(html)
document.getElementById("d").innerHTML = html;
</script>

 

当url中有空格时,报unterminated string constant,去掉空格则不报错

解决办法:

var html = "<span onclick=\"onMouseDown(this,‘"+url+"‘)\">myspan</span>"; 

猜测原因,未加双引号时js判断不出函数的终止位置

 

js unterminated string constant,布布扣,bubuko.com

js unterminated string constant

原文:http://leopold.blog.51cto.com/3548309/1384002

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!