我遇到的问题是,当我使用JavaScript将HTML文件获取到另一个HTML文件中时,背景图像变为不可见。但是,当我打开带有背景图像的文件时,该图像是可见的。
为了使这一点易于理解,我想使用javascript在first.html中包含second.html(带有背景图像),而图像不可见。
First.html(主要)
<html>
<head>
<script>
$(function(){
$("#second").load("second.html");
});
</script>
</head>
<body>
<div id="second"></div>
</body>
</html>
Second.html(带图片)
<body style="background-image: url('img/dashboard-layout.png'); background-repeat: no-repeat; background-color: #303032;">
<!--Code goes here-->
</body>
这是我的工作示例first.html
<html>
<head>
<script>
$(function(){
$("#second").load("second.html");
});
</script>
</head>
<body>
<div id="second" style="height:100px;width:100%;"></div>
</body>
second.html
<div style="height:100px;width:100%;background-image: url('http://blogs.atlassian.com/wp-content/uploads/01-new-icons.png'); background-color: #303032;">
请注意,div的默认高度为0px,您需要设置div的高度才能使用此功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句