简体   繁体   English

用javascript动态链接

[英]dynamic link with javascript

During my searching on this topic, I would like to have some help. 在我搜索这个主题时,我想得到一些帮助。

In my web page, I would like to build a HREF link that redirects in a precise web page depends to the current month. 在我的网页中,我想构建一个HREF链接,该链接在精确的网页中重定向,取决于当前月份。

My link is : 我的链接是:

<td><a href="/comptes/mon_compte.html?display=affilies_periode&id=${vendeur.id}&  month=javascript:monthNumber">Détails pour le mois en cours</a></td>

And my code in JS : 我在JS中的代码:

<script language="JavaScript">
    date1 = new Date();
    document.write("<p>date1</p>");
    monthNumber = date1.getMonth();
    document.write("<p>monthNumber</p>");
</script>

with the result of month, I would like to make the query dynamic like this : 与月的结果,我想使查询动态像这样:

http://localhost:8080/comptes/mon_compte.html?display=affilies_periode&id=2&***month=javascript:monthNumber***

Please, could you give me a piece of advice? 拜托,你能给我一些建议吗?

Ale. 啤酒。

HTML HTML

<a href="#" id="myUniqueLinkId">name of link</a>

JS JS

var month = (new Date()).getMonth();
var myURL = 'http://domain.tld/myLocalFile.php?month=' + month + '&param=1';
document.getElementById('myUniqueLinkId').href = myURL;

Or alternatively just handle it completely at runtime: 或者只是在运行时完全处理它:

<a onclick="window.location='http://domain.tld/myLocalFile.php?month=' 
   + (new Date()).getMonth();return false;" href="#">name of link</a>

Best solution is still to handle this not in JS but in your serverside code and just generate the correct links there. 最好的解决方案仍然是处理这个问题,而不是在JS中,而是在服务器端代码中,只需在那里生成正确的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM