在触发链接之前我需要一个YES / NO提示符。我已经尝试了几种我找到的解决方案,但没有一种解决方案。除了confirm()之外,没有人甚至阻止链接的触发。但是confirm()没有给我机会改变东西或改变按钮标签。 我想根据用户选择的内容为网址添加值。另一个问题是我在页面上有这些链接的列表(事件)。 任何帮助将不胜感激。
编辑1
$("a").click(function(e) {
e.preventDefault();
});
无效,在这种情况下,我不知道如何访问该网址。我只是想推迟调用网址。
编辑2 这是创建链接(cakephp)的代码:
echo $this->Html->link(
$this->Html->image('image.png',array(
'title' => __('title'),
'alt' => __('title')
)),
array(
'action' => 'action',
$eventId,
$anotherVar,
$this->Paginator->current(),
$customerId
),
array('escape' => false)
);
现在我想询问客户是/否问题,并根据客户的选择在网址中添加另一个参数。
编辑3 通过上面的代码创建的html代码:
<a href="/system/controller/function/value1/value2">
答案 0 :(得分:0)
<a href="home/about-me" onclick="return confirm('Are you sure to move to this page');">click me</a>
对任何开发者来说最简单的事情。
以下是自定义确认框的参考,
否则,如果您想要更改整个框和功能,请转到jQuery模式框,
答案 1 :(得分:0)
如果要在提交链接之前采取任何操作,可以使用jQuery.click()。此外,您可以通过
停用默认行为(在链接之后)event.preventDefault();
所以你想出类似的东西:
jQuery('a.mylink').click(function( event ){
// prevent following link
event.preventDefault();
// validation and action
});
在您通过验证并采取适当的措施后,您可以使用以下方法触发Click事件:
jQuery("a.mylink").trigger("click");
希望我帮到你。