1

有人试试这个吗?我很难让它发挥作用。

我尝试使用以下两者(一个或另一个)在我的模板头部初始化它:

<script>
$('div:jqmData(role="page")').live('pagebeforeshow',function(){
   jQuery("abbr.timeago").timeago();
});
</script>

<script>
jQuery(document).ready(function() {
  jQuery("abbr.timeago").timeago();
});
</script>

然后在内容部分,我尝试使用:

<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>

正如 timeago 文档所暗示的那样。

虽然我只看到July 17, 2008并没有动态时间变化。

有人知道怎么做吗?

4

1 回答 1

1

如您在此示例中所见,它有效:http: //jsfiddle.net/Gajotres/KXHBj/

HTML:

<!DOCTYPE html>
<html>
<head>
    <title>jQM Complex Demo</title>
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0"/>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>    
</head>
<body>
    <div data-role="page" id="index">
        <div data-theme="a" data-role="header">
            <h3>
                First Page
            </h3>
            <a href="#second" class="ui-btn-right">Next</a>
        </div>

        <div data-role="content">
            <abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
        </div>

        <div data-theme="a" data-role="footer" data-position="fixed">

        </div>
    </div>  
</body>
</html>   

JS:

$(document).on('pagebeforeshow', '#index', function(){       
    $(".timeago").timeago();
});
于 2013-02-01T19:54:14.920 回答