a href onClick 在页面启动时被调用(在点击链接之前)

Posted

技术标签:

【中文标题】a href onClick 在页面启动时被调用(在点击链接之前)【英文标题】:a href onClick is called on page start up (before clicking on the link) 【发布时间】:2014-08-11 12:28:52 【问题描述】:

我有一个 primefaces 数据表,其中有一列包含指向 ftp 文件的链接:

<p:column sortBy="emplacementlivrable" filterBy="emplacementlivrable">
<a href="ftp://#spec.emplacementlivrable" onclick="#respSpecController.connectToFtpServer()" target="_blank">#spec.emplacementlivrable
</a>
</p:column>

我需要连接到 ftp 服务器的方法,只有当用户点击链接时才会执行。但是当我调试时,我可以看到它在页面启动时调用了该方法,而不仅仅是在单击链接时。

是否有阻止这种行为的原因?

谢谢

【问题讨论】:

【参考方案1】:

这很奇怪,我不知道为什么。但这应该可行:

<p:commandLink value="#spec.emplacementlivrable" 
               actionListener="#respSpecController.connectToFtpServer()" 
               oncomplete="window.open('ftp://#spec.emplacementlivrable'); return false;" 
               />

【讨论】:

以上是关于a href onClick 在页面启动时被调用(在点击链接之前)的主要内容,如果未能解决你的问题,请参考以下文章