其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

js 确认 a 标签是否跳转

GG网络技术分享 2025-03-18 16:17 0


<!-- 默认使用 jquery -->

<a href=\"http://www.8hi.com.cn\">a标签</a>

<script>

$(function(){

$(\'a\').click(function(){

alert(\'ok\');

var $res = confirm(\'真的要跳转吗?\');

if(!$res){

// $(this).href(\'\'); 这种会导致 href 变为空, 下次再要点击时,不能跳转

return false;// 这样可以成功达到确认的目的,且不影响下次点击

}

});

});

</script>

标签: 下次 跳转

提交需求或反馈

Demand feedback