简体   繁体   中英

IE10: style is not taken into account appropriately when replacing div content with .html()

I have this code snippet (embedded in an angularjs app) intended to replace the content of an existing div popup.

    var scroller = $("#popoverImageViewer .scroller");

    var html = "";
    for (var i=0; i<c.length; i++) {

        var e = c[i];
        var content = $(e).html();
        var url     = $(e).css('background-image').replace(".thumb","").replace("/thumb","/fullsize");

        console.log("scope.openPopoverImageViewer ("+p+", "+index+") url = "+url);

        var sHtml = 
        "<div style=\"background-image: "+ url +"\">\n\
            <div>\n"
                +content
            +"</div>\n\
        </div>\n";
        html += sHtml;
        console.log("scope.openPopoverImageViewer ("+p+", "+index+") html = "+sHtml);
    }

    scroller.html(html);

It works on all platforms except on IE10/Windows 8 which generate folders as attributes as follows:

在此处输入图片说明

Any idea why ?

Ok, just realized that IE10 code snippet…

   var url = $(e).css('background-image');

returns url in the form of url("that_very_url"} with extraneous double quote, hence the issue afterwards, where IE10 thinks the first double quote closes the style attribute, the remaining of the url generate extraneous attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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