8
<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我们得到下一个值 - 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引号?

4

2 回答 2

29

如果不起作用,var text = text.replace(/&quot;/g, '\\"');请检查其他线路,因为它对我有用。

于 2014-08-22T10:04:18.507 回答
7

" 在字符串写入 '\" 之前也需要一个转义字符

 var text = text.replace(/&quot;/g, '\\"');
于 2014-08-22T09:29:58.983 回答