使用 jQuery 删除部分文件名
我想删除这样的文件名: IMG_6903.JPG&width=504
到:
IMG_6903.JPG
...
我的脚本看起来像这样:
$(function(){
$('#exposure img').each(function(){
var $imgSrc = this.src.split('&');
$(this).wrap('<a rel="lightBox" />')
.parent().attr("href", ""+$imgSrc);
});
});
但它不起作用...我该怎么做?
I want to strip a filename like this:
IMG_6903.JPG&width=504
to:
IMG_6903.JPG
...
My script looks like this:
$(function(){
$('#exposure img').each(function(){
var $imgSrc = this.src.split('&');
$(this).wrap('<a rel="lightBox" />')
.parent().attr("href", ""+$imgSrc);
});
});
But it doesn't work... How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用split
数组[0]将是IMG_6903.JPG
use split
array[0] will be IMG_6903.JPG
您分割字符串,但尝试使用数组而不是第一个元素。试试这个
希望这有帮助。
You split the string but try using the array instead of the first element. Try this
Hope this helps.