2017-01-14 75 views
0

我有<tr id="tr_color" >,我想這樣做使得當我點擊該td中的按鈕「活動帳戶」時,值「1」將添加到列中'active_account'在數據庫中,這與我一起工作。 tdbackground-color也會變成藍色,問題在這裏!不隨我改變。使用JavaScript/ajax點擊按鈕更改特定TD的背景顏色

的JavaScript

<script type="text/javascript"> 
function active_user_account() { 
    jQuery.ajax({ 
     url: "check_data.php", 
     data:'conf_data='+ document.getElementById("active_account").value + '&id='+ document.getElementById("id_this_user").value, 
     type: "POST", 
     success:function(data){ 
      document.getElementById("tr_color").style.backgroundColor = "blue !important"; 
     }, 
     error:function(){} 
    }); 
} 
</script> 
+0

TR或TD?你的代碼中有,但標題中有'具體的TD背景'? – sinisake

回答

0

你不能在使用JavaScript添加樣式!important。更改爲

document.getElementById("tr_color").style.backgroundColor = "blue"; 

它應該工作。另外,如果你確實需要使用!important,嘗試用一類,而不是這樣做:

document.getElementById("tr_color").className += " importantClass"; 

與下面的CSS:

.importantClass { background-color: blue !important; } 
+0

同樣的問題,當我添加類像你說什麼不工作!每當我點擊按鈕添加一個新的類在tr :( –

+1

@BudoorAyhd你可以讓小提琴顯示問題? –