是否可以用其他颜色覆盖背景图像?

时间:2014-04-07 12:57:55

标签: javascript jquery html css background

我现在想要用另一种颜色覆盖背景图像吗?在我的情况下,我想动态创建4个复选框,当选中这些复选框时,我希望输入字段的颜色发生变化。我试图通过下面的代码修复它,但似乎无法正常工作。

Live Demo

Jquery的:

var $div = $('<div />')
$('<input/>', {
        "type": "text",
            "class": "checkBoxCard"
    }).appendTo($div);


$("#Getbtn").on("click", function () {

        CheckBoxesChecked();

        $('#modalDialog').dialog("close");
    });

function CheckBoxesChecked() {
        var numAll = $('input[type="checkbox"]').length;
        var numChecked = $('input[type="checkbox"]:checked').length;

        if (numChecked == numAll) {

            $('.checkBoxCard').css("background-color", "yellow");
        }
    }

CSS:

.checkBoxCard {
background-image: url(http://static3.depositphotos.com/1004899/246/i/950/depositphotos_2465679-Cream-handmade-sheet-of-paper.jpg);
}

1 个答案:

答案 0 :(得分:0)

这适用于现代浏览器,IE9 +:

.checkBoxCard {
  background: #eee url(img.png) 0 0 no-repeat;
} 

.checkBoxCard:checked {
    background-image: none;
    background-color: yellow;
}
相关问题