0

我这里的逻辑有点问题,我有一个激活停用按钮,这将使 ajax 检查停用按钮的data[i].subj_status或状态subject is = 0是否为灰色,激活是否为蓝色 这是代码

  var counter_sub = 0 ;

     var html;



              $.ajax({
                        type:'POST',
                        url:'add_subject.php',
                   dataType:'json',
                       data:{'func_numbr':'2'},
                    success:function (data){
                      var activator;

                      var disabler;


                       $.each(data, function(i, item) {


                        if(data[i].subj_status == "0" ){
                            activator = "";
                          disabler = "";


                        }
                        else if(data[i].subj_status == "1" ){

                          activator = "inactiveButton";
                          disabler = "disabled='disabled'";
                        }

                        html = "<tr>";

                        html += "<td><lable>Subject: </label><input type='text' name='subject["+counter_sub+"]' rel='"+data[i].subj_id+"' value='"+data[i].subj_name+"'></td>";
                        html += "<td><input type='button' id='activate' name='active' class='button active "+activator+"' value='Active' "+disabler+"> ";
                        html += "<input type='button' id='inactivate' name='active' class='button inactive "+activator+"' value='Inactive'></td>";
                        html += "</tr>";
               $('#curr-elem-tble').append(html);

               counter_sub = counter_sub +1;
              });
                    }     
             });

CSS:

.inactiveButton{

background:gray !important;
cursor:text;

}

但不幸的是,如果状态等于 1,它们都变成了蓝色。请帮帮我。tnx 在高级。

4

1 回答 1

0

与转义序列一起使用

disabler = "disabled=\"disabled\"";
于 2012-11-28T11:35:37.790 回答