数据属性在动态添加时不以所需的格式呈现,不转义双引号
Data attribute not rendering in the desired format when added dynamically ,not escaping double quotes
我尝试使用某些数据属性动态添加div标签,但数据属性未以正确的格式呈现。请在下面找到代码
$('<a href="#" id="opendialog2" data-role="button">Open Dialog2</a><div id="inlinecontent2" style="display:none" data-options="{"mode":"blank","headerText":"Yo","headerClose":true,"blankContent":true}"><ul data-role="listview"><li>Some</li><li>List</li><li>Items</li></ul><a rel="close" data-role="button" href="#">Close</a></div>').appendTo('#myDiv')
div inlinecontent2 呈现为
<div mode":"blank","headertext":"yo","headerclose":true,"blankcontent":true}"="" data-options="{" style="display: none;" id="inlinecontent2">
数据选项属性渲染所有混乱
我希望让它呈现如下
<div id="inlinecontent" style="display:none" data-options='{"mode":"blank","headerText":"Yo","headerClose":true,"blankContent":true}'>
您需要转义引号(不同):
$('<a href="#" id="opendialog2" data-role="button">Open Dialog2</a><div id="inlinecontent2" style="display:none" data-options=''{"mode":"blank","headerText":"Yo","headerClose":true,"blankContent":true}''><ul data-role="listview"><li>Some</li><li>List</li><li>Items</li></ul><a rel="close" data-role="button" href="#">Close</a></div>').appendTo('#myDiv')
您需要转义引号:
$('<a href="#" id="opendialog2" data-role="button">Open Dialog2</a><div id="inlinecontent2" style="display:none" data-options="{'"mode'":'"blank'",'"headerText'":'"Yo'",'"headerClose'":true,'"blankContent'":true}"><ul data-role="listview"><li>Some</li><li>List</li><li>Items</li></ul><a rel="close" data-role="button" href="#">Close</a></div>').appendTo('#myDiv')
相关文章:
- 如何使用javascript或html下载PDF格式的填写表单
- 货币代码为欧元-金额的格式不应包含小数
- 在JavaScript中输出转义字符
- 转义符不能与innerHTML一起使用
- Json数据包含日期和时间格式
- Javascript日期格式类似于ISO,但本地
- Rails 3.2 js.erb文件转义js
- 更改angularjs中的日期-时间格式
- 将日期时间从json转换为可读格式
- NodeJS日期格式不起作用
- 我能得到正确的格式吗
- PHP:显示sqlite数据库中的html格式数据,使用tinymce保存
- 使用正则表达式将输入格式设置为单字符逗号、单字符逗号等
- 将日期和时间转换为UTC格式的日期-Javascript
- Javascript格式UTC日期
- 元素的内容必须由格式正确的字符数据或标记组成
- Datetime格式为Friendly Time.Moment JS输出错误
- 数据属性在动态添加时不以所需的格式呈现,不转义双引号
- 从服务器到客户端发送 JSON 格式的 HTML 时,我是否应该转义内容
- 如何从日期格式转义单词