Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
用javascript替换部分文件名_Javascript_Image_Responsive Design - Fatal编程技术网

用javascript替换部分文件名

用javascript替换部分文件名,javascript,image,responsive-design,Javascript,Image,Responsive Design,我想根据屏幕大小加载不同的图像,我想用javascript替换文件名中的文本可以很好地完成这一任务,只要我正确地命名了相应的图像。我很接近这个,但close不会阻止它 Javascript: if ($(window).width() > 960) { $("div:contains(_small.jpg)").html(function (i, currentVal) { return currentVal.replace("_small.jpg", "_lar

我想根据屏幕大小加载不同的图像,我想用javascript替换文件名中的文本可以很好地完成这一任务,只要我正确地命名了相应的图像。我很接近这个,但close不会阻止它

Javascript:

if ($(window).width() > 960) {
    $("div:contains(_small.jpg)").html(function (i, currentVal) {
        return currentVal.replace("_small.jpg", "_large.jpg");
    });
}
HTML:


正如你在我的小提琴中看到的,我让它处理文本,但不是文件名

ps-我特别不想在媒体查询类中将图像作为背景图像加载

我想根据屏幕大小加载图像

CSS
宽度和
高度设置为100%

CSS

div {
    width: 100%;
    height: 100%;   
}

完成功能:

if ($(window).width() > 960) {
    $("img[src$='_small.jpg']").each(function() {
        var new_src = $(this).attr("src").replace('_small', '_large'); 
        $(this).attr("src", new_src); 
    }); 

} else {
    alert('Less than 960');
}
不同屏幕大小的不同图像。我将更新问题以澄清
if ($(window).width() > 960) {
    $("img[src$='_small.jpg']").each(function() {
        var new_src = $(this).attr("src").replace('_small', '_large'); 
        $(this).attr("src", new_src); 
    }); 

} else {
    alert('Less than 960');
}