jQuery的获取文档中的所有HREF URL和截断或将它们分割 [英] jQuery get all href urls in a document and truncate or split them

查看:106
本文介绍了jQuery的获取文档中的所有HREF URL和截断或将它们分割的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是快把我逼疯了。

我是通过PHP动态创建一个eBay商店的菜单。

I have an ebay store menu which is created dynamically via php.

的URL是这样的:

 http://stores.ebay.co.uk/somestore/Golf-Shoes-/_i.html?_fsub=3831075010

有几个这样,出于某种原因,我的分裂不工作,我想最后的斜线后删除这些数据。

There are several of these, and for some reason my split is not working, I am trying to remove the data after the last slash.

    $('.MenuItem a:odd').each(function() {
    var $href = $(this).attr('href');
    $href.split('_')[1];
    console.log($href);
});

这是我的逻辑应该返回: http://stores.ebay.co .UK / somestore /高尔夫鞋 - /

By my logic that should return: http://stores.ebay.co.uk/somestore/Golf-Shoes-/

我在这里做了一个小提琴: http://jsfiddle.net/lharby/HA793/1 /

I've made a fiddle here: http://jsfiddle.net/lharby/HA793/1/

我不能太遥远。我试着用其他字符分割得来检验这个理论,并似乎没有任何工作。我要去哪里错了。

I cant be too far off. I've tried splitting by other characters too to test the theory, and nothing seems to work. Where am I going wrong.

推荐答案

所有你缺少的是一个赋值操作符

All you're missing is an assignment operator

$ HREF = $ href.split(_)[0];

这篇关于jQuery的获取文档中的所有HREF URL和截断或将它们分割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆