Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
JQuery通配符替换URL_Jquery - Fatal编程技术网

JQuery通配符替换URL

JQuery通配符替换URL,jquery,Jquery,我需要替换这个URL http:///prod/ap4s/appleproducts/iphone/4S 与 http:///prods.aspx?prod_id=ap4s 从现有url获取productId“ap4s”,并将其作为querystring传递 ('a').each(function(){ $(this).attr('href') <--- Modify href here.. } ('a')。每个(函数(){ $(this.attr('href')嘿,罗依,

我需要替换这个URL

http:///prod/ap4s/appleproducts/iphone/4S

http:///prods.aspx?prod_id=ap4s

从现有url获取productId“ap4s”,并将其作为querystring传递

('a').each(function(){
   $(this).attr('href')    <--- Modify href here.. 
}
('a')。每个(函数(){

$(this.attr('href')嘿,罗依,谢谢你的回答。这里只做了更正。要设置JQuery属性,我们需要使用$(this.attr(old,new)。我们不能像$(this.attr(old)=new;:)那样设置它。再次感谢。我在这里遇到了另一个问题,您提供的索引在IE和Chrome中的工作方式有所不同。似乎IE从0开始,Chrome从1开始。我仍在尝试进一步验证这一点,这似乎是一个比较棘手的问题。但是,我可能必须尝试一些不同的解决方案(嘿,罗依,谢谢你的回答。这里只有更正。要设置JQuery属性,我们需要使用$(this.attr(old,new)。我们不能像$(this.attr(old)=new;:)那样设置它。)。再次感谢。我在这里遇到了另一个问题,您提供的索引在IE和Chrome中的工作方式有所不同。似乎IE从0开始,Chrome从1开始。我仍在尝试进一步验证这一点,这似乎是一个比较棘手的问题。但是,我可能必须尝试一些不同的解决方案(
$('a').each(function(){
   $(this).attr('href','http:///prods.aspx?prod_id='+$(this).attr('href').split('/')[3]) 
}