javascript - 模拟Javascript函数中的href点击?

标签 javascript jakarta-ee dom-events href

我在 jsp 的遗留项目中有以下代码:

<tr>
    <th colspan="2">Customer</th>
    <td colspan="2">
      <a href="myAction.do" target="view">CustomerLink</a></td>
</tr>
当我们单击 CustomerLink 时,我希望对行为进行少许修改。我只想在执行操作之前在 Javascript 函数中进行一些处理。 我没有得到如何模拟 Javascript 函数中的 href 链接行为?
我试过的: -
<tr>
    <th colspan="2">Customer</th>
    <td colspan="2">
      <a href="javascript:customerLinkClicked('myAction.do')" target="view">CustomerLink</a></td>
</tr>
//Javascript函数
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 - 模拟Javascript函数中的href点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12852549/

相关文章:

javascript - 使用动态生成的 DOM 属性解释这个 IE 事件绑定(bind)机制

javascript - 在javascript中连接4算法

javascript - HTML Canvas - 文本阴影在 Mac 上不起作用?

javascript - 滚动时如何阻止 Material ui 表行中的按钮溢出?

java - 将对象从 Java(BlazeDs) 服务器传递到前端 Flex 应用程序

javascript - 同一页面上的多个表单使用相同的指令和元素指令中的一个表单

javascript - 如何使用柯里化(Currying)函数删除事件监听器

javascript - 将授权和安全性应用于 RIA

java - 如何协调部署到 WebLogic 集群中多个服务器的单个 ejb 计时器?

java - 在 JEE 中 24 小时后从 MySQL 中删除一行?