在同一个类别的href前面加上 [英] prepend href with same class
问题描述
我的页面上有以下代码...
I have the following code on the my page...
<a href="javascript:change_product_photo(2);"><img id="alternate_product_photo_2" style="border-color:#666666;" src="/v/vspfiles/photos/00-6189-2S.jpg" border="1">
有时<a href="javascript:change_product_photo(4);">
可能会更多,并且每个索引的索引号都更高,例如5、6、7等.
Sometimes there could be more of the <a href="javascript:change_product_photo(4);">
and each one would have a higher index number 5, 6 ,7, etc.
我想为每个带有javascript:change_product_photo(x)
(其中x为索引)的href实例删除change_product_link
中的两个"_",但保留(x)
索引
What I want to do is for each and every instance of the href with javascript:change_product_photo(x)
(where x is the index) remove both "_" from the change_product_link
but leave the (x)
index
我的想法是先向包含javascript:change_product_photo
的所有href中添加一个类,然后使用该类修改所有href; s,但我对如何执行此操作一无所知.
My thought was to first add a class to all hrefs that contain javascript:change_product_photo
and then modify all of the href;s with that class but I am lost on how to do this.
这是我到目前为止所得到的...
Here is what I got so far...
$("a[href*='javascript:change_product_photo']").addClass('link_fix');
现在我不知道如何从网址中删除"_".
Now I don't know how to remove the "_" from the url.
推荐答案
尝试...
$("a[href^='javascript:change_product_photo']")
.addClass('link_fix')
.attr('href', function(i,v){
return v.replace('_','');
})
根据评论进行编辑,请注意href*=
已更改为href^=
(从选择器开始)
edit based on comment, note the href*=
has changed to href^=
(start-with selector)
并从jQuery 1.4开始阅读'Easy Setter Functions'function(i,v){...}
. x
这篇关于在同一个类别的href前面加上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!