我希望禁用功能不同功能我的代码兼容和功能不同

时间:2018-01-14 09:25:44

标签: javascript php jquery

我不想要不同的系统,我的代码既可以兼顾也可以。任何人帮我解决这个问题我尝试用JavaScript编辑,但我是JavaScript初学者。如果有人帮助我,我将不胜感激。我试着用if else来解决这个问题但是无法调试..

 <?php 
      $status_query1 = "select * from  like_unlike WHERE userid= '$id' and profile_id= '$profile_id' and type ='1'";
        $status_result1 = mysqli_query($conn , $status_query1) or die(mysqli_error($conn));
            $status_row1 = mysqli_fetch_array($status_result1 , MYSQLI_ASSOC);
            $count_status1 = $status_row1['type'];

      if($count_status1 == NULL){
                $type2 = $status_row1['type'];                  
        ?>
                <input type="button" value="Like" id="like_<?php echo $profile_id; ?>" class="like" style="<?php if($type == 1){ echo "color: #ffa449;"; } ?>" />&nbsp;(<span id="likes_<?php echo $profile_id; ?>"><?php echo $total_likes; ?></span>)&nbsp;
     <?php
     }
     if($count_status1 == '1'){
     ?>

                    <input type="button" value="Unlike" id="unlike_<?php echo $profile_id; ?>" class="unlike" style="<?php if($type == 0){ echo "color: #ffa449;"; } ?>" />&nbsp;(<span id="unlikes_<?php echo $profile_id; ?>"><?php echo $total_unlikes; ?></span>)
                <?php   } ?>

/ * Javascript * /

$(document).ready(function(){

    // like and unlike click
    $(".like , .unlike").click(function(){
        var id = this.id;   // Getting Button id
        var split_id = id.split("_");

        var text = split_id[0];
        var profile_id = split_id[1];  // postid

        // Finding click type
        var type = 0;
        if(text == "like"){
            type = 1;
        }else{
            type = 0;
        }

        // AJAX Request
        $.ajax({
            url: 'likeunlike.php',
            type: 'post',
            data: {profile_id:profile_id,type:type},
            dataType: 'json',
            success: function(data){
                var likes = data['likes'];
                var unlikes = data['unlikes'];

                $("#likes_"+profile_id).text(likes);        // setting likes
                $("#unlikes_"+profile_id).text(unlikes);    // setting unlikes

                if(type == 1){
                    $("#like_"+profile_id).css("color","#ffa449");
                    $("#unlike_"+profile_id).css("color","lightseagreen");
                }

                if(type == 0){
                    $("#unlike_"+profile_id).css("color","#ffa449");
                    $("#like_"+profile_id).css("color","lightseagreen");
                }   
            },
            error: function(data){
                alert("error : " + JSON.stringify(data));
            }
        });    
    });       
});

1 个答案:

答案 0 :(得分:1)

// like and unlike click
$(".like , .unlike").click(function(){

// like and unlike click
$(".like").click(function(){

unlike事件

中删除click课程