我正在使用现有的API将文本区域中的数据预加载。我遇到的问题是,当我在data-trix-attachment属性中有一个json对象时,我的HTML代码中断了,并且浏览器无法读取它,因为单引号内有双引号。
如果将属性更改为单引号,则必须将我的data-trix-attachment json对象双引号引起来,这将使我面临同样的问题。
下面的片段是动态生成的,因此修改它的权限非常有限。有人会对我如何格式化以便浏览器可以读取它有想法吗?
<input id="139" value="<div><a data-trix-content-type="image/png"
data-trix-attachment="{'contentType':'image/png','filename':'Screen Shot 2015-11-16 at 11.36.45 AM.png','filesize':9291,'height':77,'href':'http://localhost/gu/attachments/2015-11-161447699983504-Screen Shot 2015-11-16 at 11.36.45 AM.png','url':'http://localhost/gu/attachments/2015-11-161447699983504-Screen Shot 2015-11-16 at 11.36.45 AM.png','width':305}" href="http://localhost/gu/attachments/2015-11-161447699983504-Screen Shot 2015-11-16 at 11.36.45 AM.png"><figure class="attachment attachment-preview png"><img src="http://localhost/gu/attachments/2015-11-161447699983504-Screen Shot 2015-11-16 at 11.36.45 AM.png" height="77" width="305"><figcaption class="caption">Screen Shot 2015-11-16 at 11.36.45 AM.png <span class="size">9.07 KB</span></figcaption></figure></a></div>" type="hidden" name="content"> <trix-editor input="139"></trix-editor>
您希望将内引号替换为HTML文字。这被称为转义。
双引号的HTML文字代码为"
。
编辑:只是为了澄清,我的意思是第二层引号。您的代码变为(截断):
<input id="139" value="<div><a data-trix-content-type="image/png" data-trix-attachment="{[JSON DATA]}" href="http://[URL]"></a></div>">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句