javascript - jQuery .html ('<img>' ) 在 FF 和 Opera 中不起作用

标签 javascript jquery html firefox

这一行

jq("#description" + tourId).html('<b>Opis: </b>  '+ data);

在 IE、Firefox 和 Opera 中运行良好。

但是这个

jq("#images" + tourId).html('<img src=\"img\\gbflag.png\"/>');

仅适用于 IE。 Firefox 和 Opera 不显示图像。你知道为什么吗?

这是我的其余代码:

<script type="text/javascript">
var jq = jQuery.noConflict();
function showImages(tourId) {
    jq(function() {
        jq.post("/TourWebSpring/tourImages.html",
            {tourId: tourId},
        function(data) {
            ...
            ...
            jq("#images" + tourId).html('<img src=\"img\\gbflag.png\"/>');
        });
    });
}

function showDetails(tourId) {
    jq(function() {
        jq.post("/TourWebSpring/tourDetail.html",
            {tourId: tourId},
        function(data) {
            ... 
            jq("#description" + tourId).html('<b>Opis: </b>  '+ data);
        });
    });
}

最佳答案

我认为问题可能是您在 img 目录后使用了错误的斜杠,而且我认为您不需要转义双引号,因为您是用单引号定义字符串.尝试:

jq("#images" + tourId).html('<img src="img/gbflag.png"/>');

关于javascript - jQuery .html ('<img>' ) 在 FF 和 Opera 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11922082/

相关文章:

jquery - 如何获取我的最后一个类元素数据 ID?

javascript - 如何在vuejs中动态添加文本框并设置唯一的v模型?

javascript - 按钮在 Firefox 中无法正确显示

php - 更好地在表单提交按钮上使用jquery?

javascript - 使用当前 url 在 javascript 中保存 Cookie 在 PHP 中用双引号 $_COOKIE 保存

javascript - Window.Print() 在 chrome/Firefox 中不工作

jquery - 如何使用 jquery 动态构建包含多个 <span> 的 .text 节点

javascript - 对象原型(prototype)和继承

javascript - 使用 Javascript 删除 div 内的文本

Click for CSS 上的 JQuery 不起作用