在javascript函数中模拟href单击? [英] Simulate the href click in javascript function?
本文介绍了在javascript函数中模拟href单击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jsp中的遗留项目中有以下代码
I have below code in my legacy project in jsp
<tr>
<th colspan="2">Customer</th>
<td colspan="2">
<a href="myAction.do" target="view">CustomerLink</a></td>
</tr>
当我们点击CustomerLink时,我希望对行为进行少许修改。我只想在点击动作之前在javascript函数中进行一些处理。 我没有得到如何模拟javascript函数中的href链接行为?
I want little modification in behaviour when we click CustomerLink. i just want to do some processing in javascript function before hitting the action. I am not getting how to simulate the href link behaviour in javascript function?
我尝试过的事情: -
What i Tried:-
<tr>
<th colspan="2">Customer</th>
<td colspan="2">
<a href="javascript:customerLinkClicked('myAction.do')" target="view">CustomerLink</a></td>
</tr>
// javascript function
// javascript function
function customerLinkClicked(path)
{
// simulate the href link behaviour, not sure how to do this
}
推荐答案
<a href="javascript:customerLinkClicked('myAction.do')" target="view">CustomerLink</a>
<script>
function customerLinkClicked(path) {
if (confirm('message'))
document.location.href = path;
}
</script>
这篇关于在javascript函数中模拟href单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文