如何实现关注

217次浏览 更新日期:2024-01-20 19:37:35 分类:问题求助 评论:2

<a href="javascript:;" id="follow" onclick="这里应该怎么写能实现关注作者">加关注</a>

<a href="这里链接是什么能跳转后天发信息" class="primary" target="_blank">发私信</a>


麻烦大神指点一下,谢谢

我来说两句
  • @oolaile 没错,就是这样
    0
    回复
  • oolaile
    oolaile 3月前
    <a href="javascript:;" id="follow" onclick="follow('{$userid}');">加关注</a>
    <a href="{U('member/messages/new_messages', array('username'=>$username))}" class="primary" target="_blank">发私信</a>
    
    
    在内容页添加如下:
    <script type="text/javascript">
    	check_follow();
    	function follow(userid) {
    		$.ajax({
    			type: 'POST',
    			url: "{U('member/index/public_follow')}", 
    			data: 'userid='+userid,
    			success: function (msg) {
    				if(msg == 1){
    					$("#follow").html('已关注');
    					layer.msg("关注成功!\n以后对方发布新文章时,会在您的会员中心显示哦!", {icon:1});
    				}else if(msg == 2){
    					$("#follow").html('加关注');
    					layer.msg("已取消关注", {icon:1});
    				}else if(msg == 0){
    					layer.msg('请先登录!', {icon:2});
    				}else if(msg == -3){
    					layer.msg('不能关注自己哦~', {icon:2});
    				}else if(msg == -1){
    					layer.msg('该用户不存在!', {icon:2});
    				}else{
    					layer.msg('非法操作!', {icon:2});
    				}
    			}
    		});
    	}
    
    	function check_follow() {
    		$.ajax({
    			type: 'GET',
    			url: "{U('api/index/check_follow', array('userid'=>$userid))}", 
    			dataType: "json", 
                success: function (msg) {
    				if(msg.status == 1){
    					$("#follow").html(msg.message);       
    			    }
                }
    		});
    	}
    	</script>
    0
    回复
作者信息
发布见解
发内容 回顶部