我有以下字符串:
$("#trip-to").after(
'<div class="disambi">' + '<div class="disambiguation-indicator"></div>' + '<div class="disambiguation-inner-wrapper">' + ' <p><strong> “'+query+ '”.</strong></p>' + ' <p><strong>Did you mean to...</strong></p>' + '<ul>' + suggest + '</ul>' + (count >= 14 ? ' <p><a class="js-disambiguation-show-more" data-parent="to">Show more locations...</a></p>' : '') + '</div>' + '</div>');
resultQuery = query;
我希望在某个条件下将上面的"to"
替换为"from"
。
我试过替换功能,但它没有给出正确的输出....
可能是因为"
和'
我错过了其他任何事情?
答案 0 :(得分:0)
为什么不将输出字符串创建为变量:
var outputStr = '<div class="disambi">' + '<div class="disambiguation-indicator"></div>' + '<div class="disambiguation-inner-wrapper">' + ' <p><strong> “'+query+ '”.</strong></p>' + ' <p><strong>Did you mean to...</strong></p>' + '<ul>' + suggest + '</ul>' + (count >= 14 ? ' <p><a class="js-disambiguation-show-more" data-parent="to">Show more locations...</a></p>' : '') + '</div>' + '</div>');
然后在变量上执行替换吗?
然后你可以简单地将修改后的字符串转储到你想要的位置:
$("#trip-to").after(outputStr);