<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判断不出函数的终止位置