最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JS how right replace `&quot` on quotes - Stack Overflow

programmeradmin1浏览0评论
<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 autocomplate in input we get nextvalue - Text &quot; TextTextText &quot; (database row have it value) but need output Text " TextTextText "

For replace &quot; on " i want make:

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

But this is not working...

Tell me please 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;
                }
    });

After autocomplate in input we get nextvalue - Text &quot; TextTextText &quot; (database row have it value) but need output Text " TextTextText "

For replace &quot; on " i want make:

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

But this is not working...

Tell me please how right replace &quot on quotes ?

Share Improve this question asked Aug 22, 2014 at 9:24 user2881809user2881809
Add a comment  | 

2 Answers 2

Reset to default 32

if not working var text = text.replace(/&quot;/g, '\\"'); check other lines becouse it worked for me.

" is also needs a escape character before in string write '\"

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

评论列表(0)

  1. 暂无评论