$('.Autocomlete1').typeahe...">

JS, how to replace `& quot` with quotes correctly

<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; } }); 

After the auto command in input we get the following value - Text &quot; TextTextText &quot; Text &quot; TextTextText &quot; (database row matters), but the output is Text " TextTextText "

To replace &quot; to " I want to do:

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

But this does not work ...

Please tell me how to replace " with quotes correctly?

+5
source share
2 answers

if var text = text.replace(/&quot;/g, '\\"'); doesnโ€™t work var text = text.replace(/&quot;/g, '\\"'); check out the other lines because it worked for me.

+13
source

"also need an escape character before write '\"

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

Source: https://habr.com/ru/post/1200910/


All Articles