Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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 从图像属性(';src';)中删除文本;_Javascript_Jquery - Fatal编程技术网

Javascript 从图像属性(';src';)中删除文本;

Javascript 从图像属性(';src';)中删除文本;,javascript,jquery,Javascript,Jquery,Im使用图像的src,但是Im获取缩略图像src,需要操纵src以获得完整大小的图像: Jquery: $(this).attr('src'); 我明白了:http://local/images/_w/image_jpg.jpg 我需要替换:\u w/要获得全尺寸图像,我如何在jQuery中执行此操作?如下: string.replace('_w/','whatever you want'); var temp $(this).attr('src'); var NewURL = temp.

Im使用图像的src,但是Im获取缩略图像src,需要操纵src以获得完整大小的图像:

Jquery:

$(this).attr('src');
我明白了:
http://local/images/_w/image_jpg.jpg

我需要替换:
\u w/
要获得全尺寸图像,我如何在jQuery中执行此操作?

如下:

string.replace('_w/','whatever you want');
var temp $(this).attr('src');

var NewURL = temp.replace("_w/", "derp");

这是假设您只想删除路径的
\u w/
部分。否则,用您需要的任何内容替换空字符串。

您可以使用Javascripts中的一个优秀的字符串操作函数,如
replace

var src_fullsize = $(this).attr('src').replace('/_w/','/');

这不是让jQuery来完成的问题,因为Javascript已经内置了一个函数

var v = $(this).attr('src').replace('_w','whatever');
$(this).attr('src', v );
像这样

var og_source = $(this).attr('src');
var replacement_text = "_big"
$(this).attr('src',$og_source.replace('_w/',replacement_text));

您需要用包含大小的字符串替换
\u w
,然后再次设置属性
src

$(this).attr('src', $(this).attr('src').replace('_w', '100x100'));
您可以这样做:

var newImg = $('#myId').attr('src').replace('_w/','');
$('#myId').attr('src', newImg);

$(文档).ready(函数(){
$(“.swap”)。单击(函数(){
var src=$(“.thumb”).attr(“src”);
src=src.replace(“/”w“,”);
$(“.thumb”).attr(“src”,src);
警报($(“.thumb”).attr(“src”);
});
});

下面是一个

不幸的是,jQuery无法做到这一点。。。。但是JavaScript可以!:)@Felix你说jQuery做不到这一点是什么意思???@mcgrailm:我想说jQuery只是一个JavaScript库,不是每个问题都是jQuery问题。但人们似乎认为jQuery不同于JavaScript,它正在发挥神奇的作用。无论如何,jQuery不提供任何字符串操作方法,因此您不能用jQuery替换字符串。@Felix ahh我知道您的point replace实际上是一个javascript函数,而不是jQuery函数
$(this).attr('src', $(this).attr('src').replace('_w', '100x100'));
var newImg = $('#myId').attr('src').replace('_w/','');
$('#myId').attr('src', newImg);
<a href="#" class="swap">Swap</a>
<img class="thumb" src="http://local/images/_w/image_jpg.jpg" />

$(document).ready(function(){

    $(".swap").click(function(){

        var src = $(".thumb").attr("src");
        src = src.replace("/_w", "");

        $(".thumb").attr("src", src);
        alert($(".thumb").attr("src"));
    });

});