【问题标题】:What's wrong with IE's modes and JQuery $.tmpl() renderingIE 的模式和 JQuery $.tmpl() 渲染有什么问题
【发布时间】:2012-08-14 19:58:31
【问题描述】:

我发现 JQuery 的 $.tmpl() 渲染在不同的浏览器中有很大的不同。主要是 IE 版本。当下面的代码放在更新面板中时,它会使用 .appendTo("#divList"); 方法引发错误。

对此有什么解决方法 - 下面的代码示例

Mozilla:成功

IE浏览器模式(IE9兼容视图),文档模式(IE9标准):成功

IE浏览器模式(IE9),文档模式(IE9标准):成功

IE浏览器模式(IE8),文档模式(IE9标准):成功

IE浏览器模式(IE7),文档模式(IE9标准):成功

IE浏览器模式(*),文档模式(IE8标准):FAIL(无渲染)

IE浏览器模式(*)、文档模式(IE7标准):FAIL

IE浏览器模式(*)、文档模式(Quirks模式):FAIL

<head runat="server"> 
 <meta http-equiv="X-UA-Compatible" content="IE=8;FF=3;OtherUA=4" /> 
 <script src="http://code.jquery.com/jquery-latest.min.js"></script>
 <script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script> 

<script type="text/javascript"> 

    $(function () {

        var a = [
            { actor: 'hanks', film: 'yo mama' },
            { actor: 'banks', film: 'men can swim' },
            { actor: 'will', film: 'men can swim' },
            { actor: 'jlo', film: 'ooogh aah' },
            { actor: 'jlo', film: 'bright yellow shadows' }
        ];

        $('#txDibaba').live("keyup", function () {
            $("#divList").empty();
            $('#PM_tmpl').tmpl(blep(a, 'actor', $(this).val())).appendTo("#divList"); 
        });

    });

    function blep(arr, prop, value) {
        return $.grep(arr, function (item) { return item[prop] == value }); 
    }
</script>
    <script id="PM_tmpl" type="text/x-jquery-tmpl">
    <tr>
        <td style="width:60%;text-decoration:underline;cursor:pointer;">${name}&nbsp; ${strength}&nbsp; ${film}</td>
        <td style="width:200px;"> ${actor} </td> 
    </tr>   
</script> 

<form id="form1" runat="server">


            <input type="text" id="txDibaba" /> 
            <br />

            <div id="divList" style="border:1px solid black; width:400px; padding:2px;"> 

            </div> 

</form> 

强制 IE9 模式有意义吗?

【问题讨论】:

  • 你在问什么?是的,强制 IE9 模式。有一个元标记可以做到这一点。
  • 另外,一些浏览器可能会原谅,但不要在数组或对象字面量的末尾放置 ','。浏览器应该会失败,并且会在我期望的严格模式下。

标签: internet-explorer jquery quirks-mode ie8-compatibility-mode


【解决方案1】:

我仍然不确定你在问什么,但在这种情况下你的代码被破坏了,而不是 IE。

var a = [
    { actor: 'hanks', film: 'yo mama' },
    { actor: 'banks', film: 'men can swim' },
    { actor: 'will', film: 'men can swim' },
    { actor: 'jlo', film: 'ooogh aah' },
    { actor: 'jlo', film: 'bright yellow shadows' }, //<-- get rid of that ,
];

【讨论】:

  • 天哪,感谢代码更新。问题是如何使它在 IE 版本中正确呈现。谢谢
猜你喜欢
  • 1970-01-01
  • 2011-11-24
  • 1970-01-01
  • 2011-11-01
  • 2010-10-15
  • 1970-01-01
  • 1970-01-01
  • 2014-08-24
相关资源
最近更新 更多