开发者

JQuery templates {{if}} statement doesn't work in Chrome

开发者 https://www.devze.com 2023-02-10 09:36 出处:网络
It will, however, work in IE, or Firefox.Any suggestions? Edit: IRT Pointy\'s observation:There were no errors of any kind.This page simply did not render anything more than the html that was in thes

It will, however, work in IE, or Firefox. Any suggestions?

Edit: IRT Pointy's observation: There were no errors of any kind. This page simply did not render anything more than the html that was in the section.

<html>
    <head>
        <script src="scripts/jquery-1.4.4.min.js"></script>
        <script src="scripts/jquery.tmpl.js"></script>
        <script id="template" type="text/x-jQuery-tmpl">
            <tr>                
                <td>${field1}</td>
                <td>
                    {{if field2 ==="hello" }}
                      <b>if statement</b>
                    开发者_Python百科{{else }}
                      <i>else statement</i>
                    {{/if }}
                </td>
            </tr>
        </script>
        <script type="text/javascript">
        var data = [
                        { field1: "yayayaya1", field2: "oyoyoyo1"},
                        { field1: "yayayaya2", field2: "hello"},
                        { field1: "yayayaya3", field2: "oyoyoyo3"}
                   ];               
        $(function() 
        {
            $("#template").tmpl(data).appendTo("#table1");
        });
        </script>
    </head>
    <body>
        <table id="table1">
          <thead>
            <tr>
                <th>field1</th>
                <th>field2</th>
            </tr>            
        </thead> 
        </table>
    </body>
</html>


It didn't work in Firefox (3.6) either when I tried it. But changing {{else }} to {{else}} fixed the problem in both browsers.

0

精彩评论

暂无评论...
验证码 换一张
取 消