我有<tr id="tr_color" >,我要创建它,以便当我单击该td中的“活动帐户”按钮时,值“ 1”将添加到数据库的“ active_account”列中,并且可以使用该功能。 background-colortd也将变为蓝色,这就是问题所在!不要跟我改变。

的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>

最佳答案

您不能在JavaScript中添加!important样式。更改为

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


它应该工作。另外,如果您确实需要使用!important,请尝试使用一个类来代替:

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


使用以下CSS:

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

关于javascript - 使用JavaScript/ajax在单击按钮上更改特定TD的背景颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41656160/

10-11 22:12
查看更多