本人用 jtemplate  做了数据绑定 而且数据显示了 后台改变的话 前台也即时改变 5秒一次的setTimeout() 调用绑定方法 现在想实现 如果 绑定的值 在后台改变的话 相应的改变 然后td的背景色 闪烁 这个不知道 怎么判断 怎么实现 想请 jtemplate 高人 给予帮助 小弟感激不尽  还有就是 怎么样可以直接在页面加载的时候绑定数据  我的代码如下
<script type="text/javascript" language="javascript">
       $(document).ready(function() {
           window.setInterval(function() {
               $.ajax({
                   type: "GET",
                   url: "/event/GetDate",
                   data: {},
                   contentType: "application/json",
                   datatype: "json",
                   cache: false,
                   success: function(msg) {
                       msg = msg.replace(new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+)\\)\\\\/\\"', 'g'), "$1new Date($2)");
                       var dateresult = eval(msg);
                       ApplyTemplate(dateresult);
                   }
               })
           }, 5000);
       });
        function ApplyTemplate(data) {
            $('#result').setTemplateElement('template');
            $('#result').processTemplate(data);
            setTableID();
        }
    </script>
在页面加载时 调用的话 得等5秒后才显示表格 怎么能让直接显示

解决方案 »

  1.   

    改成这样试试
    <script type="text/javascript">
        $(document).ready(function()
        {
            f();
            window.setInterval("f()", 5000);
        });    function f()
        { 
            $.ajax({
                    type: "GET",
                    url: "/event/GetDate",
                    data: {},
                    contentType: "application/json",
                    datatype: "json",
                    cache: false,
                    success: function(msg)
                    {
                        msg = msg.replace(new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+)\\)\\\\/\\"', 'g'), "$1new Date($2)");
                        var dateresult = eval(msg);
                        ApplyTemplate(dateresult);
                    }
                })
        }
        
        function ApplyTemplate(data)
        {
            $('#result').setTemplateElement('template');
            $('#result').processTemplate(data);
            setTableID();
        }
    </script>
      

  2.   

    td闪烁的例子:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>无标题页</title>
        <style type="text/css">
            .bg1{
                background-color:#ff0000;
            }
            .bg2{
                background-color:#00ff00;
            }
        </style>
        
    <script type="text/javascript">
        var ii;
        function st()
        {
            ii=window.setInterval("fc()",1000);
        }
        function fc()
        {
            var ttd = document.getElementById('td1');
            ttd.className = (ttd.className == "bg1") ? "bg2" : "bg1";
        }
        function sp()
        {
            window.clearInterval(ii);
        }</script>
    </head>
    <body ><table><tr><td id="td1" class="bg1">aaaa</td></tr></table><input type="button" value="开始" onclick="st();" />
    <input type="button" value="停" onclick="sp();" />
    </body>
    </html>
      

  3.   


    这个只是一个简单的列子 我知道 大概是这么解决 但是 问题是不知道 用什么方法 对现在 td里面的值和 json返回过来的值 做比较 然后 背景色闪烁
      

  4.   

    这个应该在success: function(msg)
                    {
                        msg = msg.replace(new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+)\\)\\\\/\\"', 'g'), "$1new Date($2)");
                        var dateresult = eval(msg);
                        ApplyTemplate(dateresult);
                    }
    的msg中,别人也看不到数据,只有你自己知道。
      

  5.   

    你可以 alert(dateresult)看看是什么结果,然后就知道怎么比较了