简体   繁体   English

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

[英]jQuery .html('<img>') doesn't work in FF and Opera

This line 这条线

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

works fine in IE, Firefox and Opera. 在IE,Firefox和Opera中运行良好。

But this 但是这个

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

works only in IE. 仅适用于IE。 Firefox and Opera do not show the image. Firefox和Opera不显示图像。 Do you know why? 你知道为什么吗?

This is the rest of my code: 这是我的其余代码:

<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);
        });
    });
}

I believe the problem may be that you are using the wrong slash after the img directory, and I don't believe you need to escape the double quote since you are defining the string with single quotes. 我相信问题可能是你在img目录后使用了错误的斜杠,我不相信你需要转义双引号,因为你用单引号定义了字符串。 Try: 尝试:

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

应该

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

you dont have to escape, so it should be: 你不必逃避,所以它应该是:

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

UPDATE UPDATE

oops, didnt notice you're using backslash.. scott points that out nicely! 哎呀,没注意到你正在使用反斜杠......斯科特指出这一点很好!

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

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