当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Window confirm redirects even on cancel

问题描述:

I've got a problem.

I have this window confirm:

<td>

<span>

<a onClick="return confirm('Opravdu si přejete odebrat školu z oblíbených?');" href="{{ path('parent/school/remove', {'school_id': school.id}) }}">

<i class="fa fa-times-circle fa-2x"></i>

</a>

{{school.name}}

</span>

</td>

But whether i click on Ok, or on Cancel, it will still proc the link in the href attribute and redirect to this action.

网友答案:

Do it like this:

<a onclick="confirm('Leave?') || event.preventDefault()" href="http://en.wikipedia.org">Wikipedia</a>

http://jsfiddle.net/DerekL/5s47wujv/

分享给朋友:
您可能感兴趣的文章:
随机阅读: