我是双引号有以下HTML传递JavaScript函数参数
<span onClick="alert('hi" more stuff')">Works</span><br/>
<span onClick='alert("Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean.")'>Works long text</span>
<br />
<span onClick='alert("Far far " away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean.")'> Doesn't work long text</span>
我的问题是,在第三onclick处理程序,我在浏览器中获取的未终止的字符串错误的麻烦。在真正的程序中,参数字符串正在生成客户端,因此所有编码都必须在那里发生。
在这个例子中,我已经尝试了"
和"
,并且在最后一个例子中工作。但他们在第一个例子
有工作示例工作在http://jsfiddle.net/photo_tom/9d43U/1/
只是用'\“'而不是 –
如果您保持您的JS从你的HTML中排除,你将能够避免在HTML属性中的JS字符串内编码引号的问题。 – zzzzBov
'span'元素不是交互式的,它们不会以默认的焦点顺序出现,您应该认真考虑使用'