[英]Is it possible to override an background image with another color?
I want to now if it is possible to override an background image with another color? 我现在想是否可以用另一种颜色覆盖背景图像? In my case I want to create 4 checkboxes dynamically, and when these checkboxes are checked I want the color of the input field changed.
在我的情况下,我想动态创建4个复选框,当选中这些复选框时,我希望输入字段的颜色发生变化。 I have tried to fix it by the code below, but it seems to not work.
我试图通过下面的代码修复它,但似乎不起作用。
Jquery: 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: CSS:
.checkBoxCard {
background-image: url(http://static3.depositphotos.com/1004899/246/i/950/depositphotos_2465679-Cream-handmade-sheet-of-paper.jpg);
}
This will work for modern browsers, IE9+: 这将适用于现代浏览器IE9 +:
.checkBoxCard {
background: #eee url(img.png) 0 0 no-repeat;
}
.checkBoxCard:checked {
background-image: none;
background-color: yellow;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.