【问题标题】:CSS styles gone after Ajax call in IE 7IE 7 中的 Ajax 调用后的 CSS 样式
【发布时间】:2010-10-19 19:24:55
【问题描述】:

我的样式在 AJAX 调用后没有被应用时遇到了问题。我的样式不在页面的

部分,它们仅在初始 Page_Load 时被 IE 识别。

如果您知道解决此问题的任何其他方法,请在此处发布。

这更多是参考,希望对某些人有所帮助。

【问题讨论】:

    标签: asp.net css ajax


    【解决方案1】:

    您还可以从 AJAX HTML 中获取样式,并将其插入头部。这是一些示例代码。在 IE8 和 Chrome 中测试。

    function enable_embedded_styles(html) {
    // Grab style content, and create new style element for it
    // Works for first set of <style></style> tags in html
    // Tested in IE and Chrome
        if (typeof(html) === 'string') {
            var beg = html.indexOf('<style>'), 
                end = html.indexOf('</style>');
    
            if (beg !== -1 && end !== -1) {
                var style = html.substr(beg + 7, end - 7 - beg); // everything between style tags
                html = html.substr(end + 8); // everything after closing style tag
    
                s = document.createElement('style');
                s.setAttribute('type','text/css');
    
                // For IE
                if (s.styleSheet) {
                    s.styleSheet.cssText = style;
                } // endif
    
                // For every other browser
                else {
                    s.appendChild(document.createTextNode(style));
                } // endelse
    
                // Append stylesheet to head
                document.getElementsByTagName('head')[0].appendChild(s);
            } // endif
        } // endif
    
        return html;
    } // endfunction
    

    【讨论】:

      【解决方案2】:

      在谷歌上搜索后,我发现moving my styles into the < HEAD> tag of the page fixes 的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-15
        • 1970-01-01
        • 2012-09-14
        • 1970-01-01
        • 2012-08-13
        • 2018-01-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多