0

我有以下字符串:

$("#trip-to").after(
            '<div class="disambi">' + '<div class="disambiguation-indicator"></div>' + '<div class="disambiguation-inner-wrapper">' + ' <p><strong> &ldquo;'+query+ '&rdquo;.</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"我尝试了替换功能,但它没有提供正确的输出....可能是因为太多"'

还有什么我错过的吗?

4

1 回答 1

0

为什么不将输出字符串创建为变量:

var outputStr = '<div class="disambi">' + '<div class="disambiguation-indicator"></div>' + '<div class="disambiguation-inner-wrapper">' + ' <p><strong> &ldquo;'+query+ '&rdquo;.</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);
于 2013-10-03T07:54:57.867 回答