IE的模式和JQuery $ .tmpl()呈现有什么问题

时间:2012-08-14 19:58:31

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

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

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

Mozilla:SUCCESS

IE浏览器模式(IE9 Compat View),文档模式(IE9标准):SUCCESS

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

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

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

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模式是否有意义?

1 个答案:

答案 0 :(得分:0)

我仍然不确定你在问什么,但你的代码在这种情况下被破坏了,而不是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 ,
];