Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery:替换所有CSS背景图像_Jquery_Html_Css - Fatal编程技术网

jQuery:替换所有CSS背景图像

jQuery:替换所有CSS背景图像,jquery,html,css,Jquery,Html,Css,我使用jQuery替换添加了标记的所有图像。如何替换添加了CSS的所有图像? 这就是我所拥有的。如果你看到的话,jQuery适用于img标记,但不适用于h1标记 JQUERY: $(document).ready(function () { $('img').each(function () { if ($(this).attr('src')) $(this).attr('src', 'http://upload.wikimedia.org/wikipedia/en/0/

我使用jQuery替换添加了标记的所有图像。如何替换添加了CSS的所有图像? 这就是我所拥有的。如果你看到的话,jQuery适用于img标记,但不适用于h1标记

JQUERY:

$(document).ready(function () {
    $('img').each(function () {
        if ($(this).attr('src')) $(this).attr('src', 'http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif');
    });
    $('h1').each(function () {
        if ($(this).attr('url')) $(this).attr('src', 'http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif');
    });
});

这应该对你有用

$('h1').css('background-image', 'url(http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif)');

这应该适合你

$('h1').css('background-image', 'url(http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif)');

您不能直接将图像显示为
h1
标记的属性。如果您想更改图像,您可能想通过调用如下内容来更改h1标记的css值:

$(this).css('background-image', 'transparent url("...")...');

不能将图像直接显示为
h1
标记的属性。如果您想更改图像,您可能想通过调用如下内容来更改h1标记的css值:

$(this).css('background-image', 'transparent url("...")...');
检查:

检查:

试试这个:

$(this).css('background-image',  'url(http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif)');
试试这个:

$(this).css('background-image',  'url(http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif)');

在你的小提琴上试过,效果很好

$('h1').filter(function() {
    return ( $(this).css('background-image') !== '');
}).css("background","url('http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif') no-repeat");

在你的小提琴上试过,效果很好

$('h1').filter(function() {
    return ( $(this).css('background-image') !== '');
}).css("background","url('http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif') no-repeat");

这通常针对所有元素,但代码应该是
'background-image',url(“…””
'background',transparent url(“…”)。
对不起,这行只是用来替换
$(This).attr('src','http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif');源于原始帖子。这通常针对所有元素,但代码应该是
'background-image',url(“…”)
'background',transparent url(“…”)。
抱歉,这行只是用来替换
$(This).attr('src','http://upload.wikimedia.org/wikipedia/en/0/0f/Red_X_Symbol.gif');来自原始帖子。