简体   繁体   English

HTML `img` 标签无法在对象 jquery 中显示为图像

[英]HTML `img` tag can't display as image in object jquery

I have data from "sugestion" var like this, this after I conevert the object "suggestion" to string.我有这样的“建议”变量的数据,这是在我将对象“建议”转换为字符串之后。

{"value":"<img src=\"http://localhost/erp/assets/images/product/123.jpg\"> 123123123 t-shirt","data":"ABC098765"}

But <img src="\\"http://localhost/erp/assets/images/product/123.jpg\\"> can't display as image, the image tag only display as text after append to但是<img src="\\"http://localhost/erp/assets/images/product/123.jpg\\">不能显示为图片,图片标签只显示为文字后追加

this is the ouput display.这是输出显示。

html += '<div class="' + className + '" data-index="' + i + '">' + formatResult(suggestion, value, i) + '</div>';

The complite script完整的脚本

    $.each(that.suggestions, function (i, suggestion) {
        if (groupBy){
            html += formatGroup(suggestion, value, i);
        }
        html += '<div class="' + className + '" data-index="' + i + '">' + formatResult(suggestion, value, i) + '</div>';
    });

the format result格式结果

Autocomplete.formatResult = function (suggestion, currentValue) {
        // Do not replace anything if there current value is empty
        if (!currentValue) {
            return suggestion.value;
        }

        var pattern = '(' + utils.escapeRegExChars(currentValue) + ')';

        return suggestion.value
            .replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/&lt;(\/?strong)&gt;/g, '<$1>');
    };

How to make the image tag as image when the output display?输出显示时如何将图像标签设为图像?

Thank you谢谢

Use this Stripslashes function to strip slash while returning suggestion.value .在返回使用此功能的stripslashes向带斜线suggestion.value May be because of the extra slashes your image is not displaying properly.可能是因为您的图像没有正确显示额外的斜线。

function stripslashes (str) {
  return (str + '').replace(/\\(.?)/g, function (s, n1) {
    switch (n1) {
    case '\\':
      return '\\';
    case '0':
      return '\u0000';
    case '':
      return '';
    default:
      return n1;
    }
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM