使用javascript动态链接

使用javascript动态链接,javascript,html,Javascript,Html,在我搜索这个主题的过程中,我想得到一些帮助 在我的网页中,我想建立一个HREF链接,在一个精确的网页中重定向到当前月份 我的链接是: <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>

在我搜索这个主题的过程中,我想得到一些帮助

在我的网页中,我想建立一个HREF链接,在一个精确的网页中重定向到当前月份

我的链接是:

<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>
拜托,你能给我一个建议吗

Ale.

HTML

<a href="#" id="myUniqueLinkId">name of link</a>
或者在运行时完全处理它:

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


最好的解决方案仍然是在服务器端代码中而不是在JS中处理这个问题,并在那里生成正确的链接。

您想创建动态链接吗?谢谢您的提示。只是一个关于#的问题,如果要成功验证,HTML标准要求具有填充的
href
属性,那么锚的意义是什么。因为
#
只指向当前页面的顶部,并且不会导致导航
href=“#”
是普遍接受的“此链接永远不会正常工作”符号。在第一个示例中,它被JS覆盖,在第二个示例中,它被绕过,取而代之的是
onclick
<a href="#" id="myUniqueLinkId">name of link</a>
var month = (new Date()).getMonth();
var myURL = 'http://domain.tld/myLocalFile.php?month=' + month + '&param=1';
document.getElementById('myUniqueLinkId').href = myURL;
<a onclick="window.location='http://domain.tld/myLocalFile.php?month=' 
   + (new Date()).getMonth();return false;" href="#">name of link</a>