单引号中的双引号

时间:2013-08-21 23:37:37

标签: html haskell yesod hamlet

我需要将json放在html属性中,如下所示:

<video id="video1" 
class="video-js vjs-default-skin" 
width="640" height="480" 
data-setup='{"controls" : true, "autoplay" : false, "preload" : "auto"}'>

哈姆雷特不理解html单引号字符串,它会创建错误消息:

意外“:” 期待“&gt;”

将字面值json添加到字符串中的html属性的推荐做法是什么?

2 个答案:

答案 0 :(得分:1)

使用&quot;

转义html中的引号
<video id="video1" 
class="video-js vjs-default-skin" 
width="640" height="480" 
data-setup='{ &quot;controls&quot;:true,&quot;autoplay&quot;:false,&quot;preload&quot;: &quot;auto&quot;}'>

答案 1 :(得分:0)

HTML规则使用的属性语法是正确的,并且属性值通过JSON语法是正确的,因此如果某些软件无法处理它,请检查其文档中是否存在适用的限制和/或提交错误报告。

如果问题确实是当属性值是单引号时软件无法处理HTML属性规范,请在其周围使用双引号并在其中使用相应的单引号:

data-setup="{'controls' : true, 'autoplay' : false, 'preload' : 'auto'}"