繁体   English   中英

JS如何正确替换引号上的“&quot”

[英]JS how right replace `&quot` on quotes

<input type="text" autocomplete="off" class="Autocomlete1" name="test">

$('.Autocomlete1').typeahead({
            ajax: {
                    url: './test.php?log=test',
                    triggerLength: 1
                  },
            updater: function(item) {
                    return item;
                },
            onSelect: function(item) {

                    return item;
                }
    });

input自动编译后,我们得到nextvalue - Text &quot; TextTextText &quot; Text &quot; TextTextText &quot; (数据库行有值)但需要输出Text " TextTextText "

替换&quot; "我想要:

onSelect: function(item) {
  var text = item.text;
  var text = text.replace(/&quot;/g, '"');
  $('.Autocomlete1').val(text);
  return item;
}

但这不起作用......

请告诉我如何正确的更换&quot的报价?

如果没有工作var text = text.replace(/&quot;/g, '\\\\"');检查其他行,因为它对我有效。

“在字符串写入'之前还需要一个转义字符'\\”

 var text = text.replace(/&quot;/g, '\\"');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM