[英]Javascript add multiple background images using HTML DOM or Jquery
So basically, I'm trying to have a table with a background, and sometimes a background is added on top.所以基本上,我试图有一个带背景的表格,有时会在顶部添加背景。 Is there a way to add a background in Javascript, but keep the old one?
有没有办法在 Javascript 中添加背景,但保留旧的?
You can use the background-image
CSS property, which can be given multiple images.您可以使用
background-image
CSS 属性,可以给定多个图像。 The first background specified will be on the top and the last one will be on the bottom.指定的第一个背景将位于顶部,最后一个背景将位于底部。
document.querySelector("button").addEventListener("click", function(e){ document.querySelector("table").style.backgroundImage += ",url(https://www.w3schools.com/css/paper.gif)"; }, {once: true});
<table style="height: 100px; width: 100px; border: 1px solid black; background-image: url(https://www.w3schools.com/css/img_flwr.gif);"> </table> <button> Add Image </button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.