JQuery 通过将 HTML 放入“标签”来自动完成格式设置回复
我正在使用 JQuery 自动完成功能并发送带有“标签”和“值”的响应。 我正在尝试让标签具有 HTML 格式。 json_encode 转义了我试图传递的 html 格式。
我应该采取不同的做法吗?如何使 json_encode 不转义 html 格式(它将“/”更改为“\/”)?
示例代码:
$return[$i]['label'] = $row['text'];
$return[$i]['label'] = "<span style='font-weight:bold;'>" . $row['text'] . "</span> - " . row['name'];
json_encode($return);
当我手动检查 url 响应时,我可以看到他将“”转义为“<\/span>”
I'm using JQuery auto-complete and sending a response with "label" and "value".
I'm trying to get the label to have formatted HTML. The json_encode escapes the html formatting I'm trying to pass through.
Should I do this differently? How can make json_encode not escape the html formatting (it changes "/" to "\/")?
Example code:
$return[$i]['label'] = $row['text'];
$return[$i]['label'] = "<span style='font-weight:bold;'>" . $row['text'] . "</span> - " . row['name'];
json_encode($return);
and when I just check the url response manually, I can see he's escaping the "" to "<\/span>"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您使用的是哪种自动完成功能。如果您使用 http://jqueryui.com/demos/autocomplete/,您的问题不是 json标签默认不支持 html
标签始终被视为文本,如果您希望标签被视为 html 可以使用 Scott González 的 html 扩展 。这些演示都侧重于源选项的不同变体 - 查找与您的用例相匹配的选项,然后查看代码
您可以执行类似的操作。代码的作用是以黄色显示自动完成匹配文本。
I am not sure which auto complete you are using. If you are using http://jqueryui.com/demos/autocomplete/, your problem is not json the label doesn't support html by default
The label is always treated as text, if you want the label to be treated as html you can use Scott González' html extension. The demos all focus on different variations of the source-option - look for the one that matches your use case, and take a look at the code
You can do something like this. What the code is doing is showing the autocomplete matching text in yellow.