Javascript抓住document.URL的最后一部分? [英] Javascript to grab last part of the document.URL?

查看:56
本文介绍了Javascript抓住document.URL的最后一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想抓住当前网址的最后一部分:

I am trying to grab the last part of the current url:

网址: http://example.com/test/action

我正试图抓住行动。

该结构中的URL始终一致。但它最后可能会有一些额外的参数。

The URL is always consistent in that structure. But it may have some extra params at the end.

这是使用原型框架的rails应用程序。在rails中它将是params [:id]。

This is in a rails app using the prototype framework. In rails it would be params[:id].

推荐答案

你可以简单地使用。split() window.location.href 上,抓住最后一个条目。

You could simply use .split() on window.location.href, and grab the last entry.

示例:

var lastPart = window.location.href.split("/").pop();

这篇关于Javascript抓住document.URL的最后一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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