jQuery在Magento中不起作用。我想要显示倒计时时间。这是行不通的。这是我的site link。这是第二个ID,并且具有时差值。它打印了值,但JavaScript没有显示时间计数,就像每日交易一样。
<script type="text/javascript">
function updateClock(id)
{
var pid = id;
var currentSeconds1 = jQuery("#hello" + pid ).val();
mySeconds = currentSeconds1 - 1;
jQuery("#second" + pid ).val(mySeconds);
alert(currentSeconds1);
if(mySeconds == 0){
location.reload();
}
else{
var currentdays = Math.floor(mySeconds/86400);
var remainiday = mySeconds%86400;
var currentHours = Math.floor(remainiday/3600);
var myHours = remainiday%3600;
var currentMinutes = Math.floor(myHours/60);
var currentSeconds = myHours%60;
// Compose the string for display
currentHours = (currentHours < 10? '0' : '') + currentHours;
currentMinutes = (currentMinutes < 10? '0' : '') + currentMinutes;
currentSeconds = (currentSeconds < 10? '0' : '') + currentSeconds;
var currentTimeString = currentdays + ' Days ' + currentHours + "h : " + currentMinutes + "m : " + currentSeconds +"s";
var t = jQuery("#clock" + pid ).html(currentTimeString);
}
}
</script>
和magento代码
<?php foreach ($productCollection->getItems() as $_product): ?>
<div class="time-left" style="font-weight: bold; color:#ff0000; font-size: 13px;">Time Left :
<span id="cl"></span>
<?php
$date1 =date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
$date2 = date("Y-m-d 23:59:59", strtotime($_product->getSpecialToDate()));
$timeFirst = strtotime($date1);
$timeSecond = strtotime($date2);
echo $differenceInSeconds = $timeSecond - $timeFirst;
?>
<input type="button" id="sec" value="<?php echo $differenceInSeconds ?>" /></div>
<div class="product-image">
<a href="%3C?php%20echo%20$_product-%3EgetProductUrl()%20?%3E"
title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
<img src="%3C?php%20echo%20$this-%3Ehelper('catalog/image')-%3Einit($_product,%20'small_image')-%3Eresize(161,123);%20?%3E"
width="161" height="123" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
</a>
</div>
<span id="clock<?php echo $_product->getId() ?>"></span>
<?php
$date1 =date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
$date2 = date("Y-m-d 23:59", strtotime($_product->getSpecialToDate()));
$timeFirst = strtotime($date1);
$timeSecond = strtotime($date2);
$differenceInSeconds = $timeSecond - $timeFirst;
?>
<form>
<input type="hidden" id="hello" value="12" />
<input type="hidden" id="second<?php echo $_product->getId() ?>" value="<?php echo $differenceInSeconds ?>" />
</form>
<div class="product-info">
<h3 class="product-name">
<a href="%3C?php%20echo%20$_product-%3EgetProductUrl()%20?%3E" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
<?php echo $this->htmlEscape($_product->getName()) ?>
</a>
</h3>
</div>
<?php //if($isShowDescription == 1):?>
<?php endforeach?>
答案 0 :(得分:0)
您似乎也在使用Prototype.js
并且未使用jquery noconflict
。
我查看了网页来源,并对/*var jns = jQuery.noConflict();*/
进行了评论。请检查可能是这种情况。
并将其更改为var jQuery = jQuery.noConflict();
,以便您可以根据自己的要求使用它。
最好为noConflict创建一个单独的Javascript文件,并将其包含在主jquery库之后。