if(prev_clicked)
{   
    $("#accordion li a.category").css('background-image', 'url("img/off_all_channel.png")');                    
    $("#accordion li a.comment").css('background-image', 'url("img/on_all_online.png")');                   
    $(".icha0").removeProperty("background-color");
    $(".icha0").removeProperty("opacity");
}
else
{   
   $(".icha0").css("background-color","#D5D5D2");
   $(".icha0").css("opacity","0.70");
}

我试图删除我添加的两个css属性,但似乎不工作。 尽管吗?


当前回答

<script>
        require(['jquery', 'domReady!'], function($) {
            if ($('#p_method_use_reward_points').prop('checked')) {
                $('.test').show();
                console.log('working');
            }else{
                $('.test').hide();
                console.log('not working');
            }
            $('#submit_reward').on('click', function (e){
                let getPoints = $('#custom_reward_set').val();
                let checkField = $('#custom_reward_set').prop("readonly");
                // alert(getPoints);
                if (!getPoints){
                    alert('PLease add reward points');
                }
                if (getPoints) {
                    $("#custom_reward_set").prop("readonly", !$("#custom_reward_set").attr('readonly'));
                    if ($('#custom_reward_set').is('[readonly]')) {
                        $("#custom_reward_set").css({
                            "background-color": "#EBEBE4",
                            "border": "1px solid #ABADB3", "cursor": "not-allowed"
                        });
                    }else{
                        $('#custom_reward_set').removeAttr('style');
                    }
                }
               e.preventDefault();

            })
        });
    </script>

其他回答

<script>
        require(['jquery', 'domReady!'], function($) {
            if ($('#p_method_use_reward_points').prop('checked')) {
                $('.test').show();
                console.log('working');
            }else{
                $('.test').hide();
                console.log('not working');
            }
            $('#submit_reward').on('click', function (e){
                let getPoints = $('#custom_reward_set').val();
                let checkField = $('#custom_reward_set').prop("readonly");
                // alert(getPoints);
                if (!getPoints){
                    alert('PLease add reward points');
                }
                if (getPoints) {
                    $("#custom_reward_set").prop("readonly", !$("#custom_reward_set").attr('readonly'));
                    if ($('#custom_reward_set').is('[readonly]')) {
                        $("#custom_reward_set").css({
                            "background-color": "#EBEBE4",
                            "border": "1px solid #ABADB3", "cursor": "not-allowed"
                        });
                    }else{
                        $('#custom_reward_set').removeAttr('style');
                    }
                }
               e.preventDefault();

            })
        });
    </script>

你可以设置属性为空:

$(“.icha0”).css(“background-color”,“”);

或者您可以更改代码使用CSS文件中定义的类:

$(".icha0").addClass('properties'); 
$(".icha0").removeClass('properties');

如果你需要删除而不是更新一个特定的属性,你可以简单地使用removeProp而不是removeProperty:

$(".icha0").removeProp("background-color");
$(".icha0").removeProp("opacity");

这实际上是一个复制粘贴从这个答案,我用它来清除CSS样式,我添加与jQuery在以前执行的函数。

删除CSS内嵌属性使用:

$('.className').css({propertyName: ''});   

要删除元素的整个内联样式,请使用:

$('.className').removeAttr('style');

或通过ID:

$('#idName').removeAttr('style');

我有这个问题,但我没有看到任何解决方案,在这里满足op。大多数解决方案建议摆脱整个风格属性,这是不值得的。

我使用jQuery的道具方法。

var styleObject = $('my-selector').prop('style'); 

styleObject.removeProperty('background-color');