激活和停用按钮颜色并禁用

时间:2012-11-28 11:26:02

标签: jquery ajax

我的逻辑有点问题,我有激活停用按钮,这将使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,则两者都变为蓝色。 plsss帮助我们。 tnx in advanced。

1 个答案:

答案 0 :(得分:0)

使用转义序列,如

disabler = "disabled=\"disabled\"";