前言
要求在网页中点击Class为“libaolq”的按钮,再询问提示“联系上面客服领取?”点是则跳转定位到当前页面id为“tiaok”的地方
方案
直接上代码,共两种方案
方式一
$(".libaolq").click(function(){ if(confirm('联系上面客服领取?')){ // 定位到id位置 window.location.hash = "#tiaok"; return true; } else { return false; } });
方式二(推荐jQuery方式)
$(".libaolq").click(function(){ if(confirm('联系上面客服领取?')){ // 定位到id位置 st = $("#tiaok").offset().top; jQuery('body,html').animate({ scrollTop: st },100); return true; } else { return false; } });
说明
请根据自己实际情况做相应修改
如有什么BUG或者疑问欢迎各路大神补充&指正