在使用 jQuery 的自动完成时,我注意到字符 &
和 '
是
转义为 &
和 '
;
例如,自动完成显示 Barbara's Straight Son
但是当我
选择此字段显示 Barbara's Straight Son
。
有什么办法可以避免这种情况吗?
感谢您的宝贵时间!
最佳答案
您需要取消转义 html 实体。我发现最简单的方法是使用这个函数:
var unescapeHtml = function (html) {
var temp = document.createElement("div");
temp.innerHTML = html;
var result = temp.childNodes[0].nodeValue;
temp.removeChild(temp.firstChild)
return result;
}
因此,在将字符串放入输入框之前,先通过此函数传递字符串。您可能必须修改自动完成插件才能执行此操作。
关于javascript - jquery 自动完成 : how to handle special characters (& and ')?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/729966/