点击后打印日期

时间:2015-10-12 08:30:09

标签: javascript jquery html datetime datepicker

我的电子商店应用程序中有发票面板。

点击我的链接后,我想打印下载日期(没有今天的日期)。是否可以轻松实现?

<a class="download-invoice" target="_blank" 
                href="?{=orderGroup.invoiceHref}">#{Download}</a>

2 个答案:

答案 0 :(得分:0)

这是一个简单的演示,您可以在单击链接时获取日期。当然,您必须以某种方式保存此日期,以便稍后显示。

&#13;
&#13;
function printDate(num) {
  var date = new Date();

 document.querySelector('.dateContainer_' + num).innerHTML = date.toDateString();
}
&#13;
<ul>
  <li>
    <a class="download-invoice" target="_blank" href="#" onClick="printDate(1)">Download 1</a>
    <span class="dateContainer_1"></span>
  </li>
  <li>
    <a class="download-invoice" target="_blank" href="#" onClick="printDate(2)">Download 2</a>
    <span class="dateContainer_2"></span>
  </li>
  <li>
    <a class="download-invoice" target="_blank" href="#" onClick="printDate(3)">Download 3</a>
    <span class="dateContainer_3"></span>
  </li>
  <li>
    etc...
  </li>
</ul>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

试试这个

&#13;
&#13;
function printDateAndDownload(hrefUrl) {
  var date = new Date();

 document.querySelector('.dateContainer').innerHTML = date.toDateString();
 
 window.open(window.url + "?" + hrefUrl)
return false;
}
&#13;
<a class="download-invoice" onClick="printDateAndDownload({=orderGroup.invoiceHref})">Download</a>

<div class="dateContainer"></div>
&#13;
&#13;
&#13;