English 中文(简体)
使用相同脚本的多个记录
原标题:multiple records using the same script
  • 时间:2012-05-22 14:35:07
  •  标签:
  • javascript

I have built a voucher website, where each voucher has a countdown timer. When you view a voucher the countdown works fine, however... I also have a summary page with multiple vouchers (using a repeat region on the recordset)... when I apply the script to each of the vouchers the script doesn t work.

HMTL :

      <h3 class="remaining"><?php echo $row_rs_dealItem[ dateend ]; ?> remaining</h3>

JAVASCRIPT外部文件:

$(document).ready(function(){
$( .remaining ).each(function(){
    var expiry_date = Date.createFromMysql($(this).html());
    var current_date = new Date();
    console.log(expiry_date.getTime() );
    console.log(current_date.getTime());
    if (expiry_date.getTime() >  current_date.getTime()) {
        var time_diff = Math.floor((expiry_date.getTime() - current_date.getTime()) / (1000*60*60));
        console.log(expiry_date.getTime() - current_date.getTime());
        console.log(time_diff);
        days_diff = Math.floor(time_diff / 24);
        hours_diff = time_diff % 24;

        $(this).html(days_diff +   days   + hours_diff +   hours );
    }
    else{
        $(this).html( expired );
    }
});
}); 

 Date.createFromMysql = function(mysql_string)
{ 
 if(typeof mysql_string ===  string )
{
   var t = mysql_string.split(/[- :]/);

  //when t[3], t[4] and t[5] are missing they defaults to zero
  return new Date(t[0], t[1] - 1, t[2], t[3] || 0, t[4] || 0, t[5] || 0);          
}

return null;   
}

JAVASCRIPT 内线:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="scripts/script.js"></script>
<script type="text/javascript">
    var reference       =  <?php echo $row_rs_dealItem[ reference ]; ?> ;
    var today           = Date.createFromMysql( <?php echo date( Y-m-d h:i:s ); ?> );
    var contractstarts  = <?php echo ($row_rs_dealItem[ datestart ] ==  0000-00-00 ) ?  ""  :  Date.createFromMysql("  . $row_rs_dealItem[ datestart ] .  ") ; ?>;
    var contractexpires = <?php echo ($row_rs_dealItem[ dateend ] ==  0000-00-00 ) ?  ""  :  Date.createFromMysql("  . $row_rs_dealItem[ dateend ] .  ") ; ?>;
</script>

我希望这个数据足够你用

感谢 谢谢

最佳回答

我意识到我有效地将代码从一页复制到另一页,

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签