j查询背景图像 URL 失败
jquery background image url failed
这不起作用....
$("#news_all ul li").css("background", "transparent url('../images/01.png') no-repeat");
但这正在工作
.news_all_item li {
background: url("../images/01.png") no-repeat scroll 0 0 transparent;
margin-bottom: 2%;
}
我的网页
<div class="news_all_item" id="news_all">
<ul>
<li><div class="news_item">Lorem Ipsum is simply dummy text of the printing and typesettiLorem Ipsum is simply dummy text</div></li>
<li><div class="news_item">Lorem Ipsum is simply dummy text of the printing and typesettiLorem Ipsum </div></li>
<li><div class="news_item">Lorem Ipsum is simply dummy text of the printing and typesetti</div></li>
</ul>
</div>
我认为这是因为相对链接。
我怀疑你的样式表可能在css文件夹中;javascript可能是用你的html编写的,在根文件夹中。
在样式表中"../images/" 是有效的,因为从文件夹 css, '../' 返回一级(到根文件夹),然后 '/images' 访问图像文件夹。但是从根文件夹中,您必须省略../(不需要再回到一个级别了)。
无论如何,如果您使用的是相对链接,请记住路径的起点是编写代码的位置。
也许路径可能有问题。如果可以的话,给出绝对路径。即 assets/style/images/01.png
)
在CSS文件中../images/01.png
可能存在,但从JS文件中../images/01.png
可能不存在
您可能有一个文件夹结构,例如。
asset
|-->style
|-->css
|-->mycss.css
|-->images
|-->01.png
|-->js
|-->myjs.js
所以这里从 CSS ../images/01.png
是有效的,但从 js 文件中同样的事情是无效
当您尝试设置背景时,您可以通过类选择器".news_all_item"而不是"#news_all_item"应用。
$(".news_all_item li").css("background", "transparent url('../Encounters/LandingPage.PNG') no-repeat");
使用背景图像而不是背景。
$("#news_all ul li").css("background-image", "transparent url('../images/01.png') no-repeat");
它
应该是background-image
,而不是background
,作为属性键。
试试这个
$( "ul#news_all> li" ).css("background", "transparent url('../images/01.png') no-repeat");
相关文章:
- 如何使失败的路由解析承诺加载不同的模板URL
- Ajax GET 请求的 URL 失败,但 hurl.it 相同 URL 的 GET 请求有效.什么给
- 当 URL 包含“#”时,jQuery Document 就绪失败
- 在暂存服务器中工作但在生产中失败的无效 URL
- j查询背景图像 URL 失败
- 在复选框中存储表单操作URL'的值,并且使用该URL发出AJAX请求会导致无法解释的失败
- ios:如何检测自定义url方案链接是否失败
- 正则表达式在URL地址测试中失败
- PhantomJS和pjscrape-在某些多个URL上失败
- Regex-正则表达式模式在URL GET参数上失败
- 两个ajax请求url(成功/失败)
- javascript可以将我的页面重定向到一个url,如果失败,则不会发出警报
- 查询字符串URL的Javascript URL验证失败
- 获取加载失败的网站的URL
- 从智能手机(iPhone)加载访问url的资源失败
- 由于交叉问题,nodejs加载URL失败
- NodeJS Passport身份验证-始终重定向到失败url
- 新建Firebase失败:第一个参数必须是有效的Firebase URL,且路径不能包含"."、&q
- for循环,加载给定的URL失败
- AngularJS Get获取带有“302 found”的图片url失败