点击后打印日期

Print date after click

本文关键字:日期 打印      更新时间:2023-09-26

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

我想在点击我的链接后打印下载日期(不是今天日期)。有可能让它变得简单吗?

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

试试这个

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

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

function printDate(num) {
  var date = new Date();
 document.querySelector('.dateContainer_' + num).innerHTML = date.toDateString();
}
<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>