跳转到内容

登录提醒判断处理

做风格的时候,某些会员才能享受的功能,如果游客点击的话,可以预先在页面里边做登录提示处理.

第一步,在页面里边增加下面的方法

function check_login(){
if("{$userdb.uid}"==""){
layer.confirm('你还没登录,不能加入,你要登录吗?', {
btn : [ '登录', '取消' ]
}, function(index) {
window.location.href = "{:get_url('login')}";
});
return false;
}
return true;
}

第二步,在点击事件那里最开始那里加入如下判断

if(check_login()!==true)return ;

举个例子,比如商城那里,用户要点击购买或者是加入购物车的话,可以在那个点击事件那里添加上面的判断代码

function BuyThisShop(totype){
if(check_login()!==true)return ; //登录判断
if((type1==0&&$(".shoptype1").length>0)||(type2==0&&$(".shoptype2").length>0)||(type3==0&&$(".shoptype3").length>0)){
layer.alert('没有选择商品类型');
}else{
var gotourl="{:urls('car/add')}?shopid={$id}&type1="+type1+"&type2="+type2+"&type3="+type3+"&num="+shopnum;
$.get(gotourl+"&"+Math.random(),function(res){
if(res.code==0){
if(totype==1){
layer.msg('成功加入购物车');
}else{
window.location.href="{:urls('car/index')}";
}
}else{
layer.alert('出错了:'+res.msg);
}
});
}
}