用javascript替换部分文件名
我想根据屏幕大小加载不同的图像,我想用javascript替换文件名中的文本可以很好地完成这一任务,只要我正确地命名了相应的图像。我很接近这个,但close不会阻止它 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
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');
}