为了账号安全,请及时绑定邮箱和手机立即绑定

Switch 或 if elseif 语句成功:function(data) ajax

Switch 或 if elseif 语句成功:function(data) ajax

PHP
明月笑刀无情 2022-10-14 16:30:21
$status = $row->status;  switch ($status){case "1":$status = '<span class="badge badge-danger">Open</span> ';break;case "2":$status=  '<span class="badge badge-secondary">On Hold</span> ';break;case "3":$status= '<span class="badge badge-success">In Progress</span> ';break;case "4":$status= '<span class="badge badge-info">Closed</span> ';break;}这是我的 php 代码中的 switch 语句;我如何做同样的现场 ajax 成功:函数(数据)这是我的ajax函数success: function(response){      //console.log(response);      $('.sub').html(response.sub);      $('.msg').html(response.msg);     //value = $(this).val(response.status); //Get the value from db;     // if elseif or swithch statetment here//      $('.sts').html('<span class="badge badge-danger">Open</span>'); //post it to html div;    }可以做什么??有什么办法可以在这里做或者我必须在编码json之前做吗?
查看完整描述

1 回答

?
qq_花开花谢_0

TA贡献1835条经验 获得超7个赞

您也可以像在 php 代码中使用它一样使用 switch case,如下所示:


    success: function(response){

      //console.log(response);

     $('.sub').html(response.sub);

     $('.msg').html(response.msg);

     var status = response.status; //Get the value from db;

    // if elseif or swithch statetment here//


    switch (status) {

        case "1":

            $('.sts').html('<span class="badge badge-danger">Open</span>');

            break;

        case "2":

            $('.sts').html('<span class="badge badge-secondary">On Hold</span>');

            break;

         case "3":

            $('.sts').html('<span class="badge badge-success">In Progress</span>');

            break;

         case "4":

            $('.sts').html('<span class="badge badge-info">Closed</span> ');

            break;


        default:

            $('.sts').html('<span class="badge badge-danger">Open</span>');

    }


}


查看完整回答
反对 回复 2022-10-14
  • 1 回答
  • 0 关注
  • 78 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信