<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
var path = location.href;
var pathone = path.slice(path.lastIndexOf("/")+1) ;
alert(pathone);
</script>
<body>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
var path = location.href;
var pathone = path.slice(path.lastIndexOf("/")+1) ;
alert(pathone);
</script>
<body>
</body>
</html>
解决方案 »
- jQuery问题啊啊啊啊啊 啊啊啊
- 100分悬赏,jquery select()方法 无法选中文本框中的值,兄弟们来看下
- 菜鸟问题3
- JS页面定时画笔
- new ActiveXObject( "WScript.Shell ")调用exe文件时,提示Automation服务器不能创建对象
- 右键菜单问题
- 下面创建的INPUT为什么不显示??
- 如何实现这样的功能 》》》 获得页面地址及复制【在线等...】
- onpropertychange为什么只能在input type=button的disable由false到true的时候触发?
- 俺要做一个在WEB上实现类似于画流程图的一个东东。求可行的技术方案!
- 简单问题:js中float大小比较
- 请教:动态添加脚本后如何取得页面的值?
function get(str) //从链接地址里提取出本文档名
{
alert(str.match(/\/([^\?/]*)(\?|$)/)[1])
}
get(location.href)
get("http://www.xxxx.com/xxx/xxx.htm")
get("http://www.xxxx.com/xxx/xxx.htm?text1=abcde&text2=fghij")
</script>
alert(this.location.pathname.match(/(?!.*[\/\\])[^\?]*/));//取得index.asp为了适应各种情况还是用这个PS:见到了一个钻石级的高手 羡慕中......
<script language=javascript>
re=/(\/|\\)(([^\\\/](?!($|\?)))+?(.(?=($|\?))))/
re.test(this.location.pathname)
alert(RegExp.$2);
</script>
gzdiablo() 你的这段正则有些问题,很多web程序的地址是镜象的,而不是直接拿文件名,所以你的程序并不是通用所有情况,比如说
http://www.csdn.net/testServlet?a=1&b=2
alert(this.location.pathname.match(/(?!.*[\/\\])[^\?]*/));//取得index.asp
但再厉害也有弱的项目 正所谓三人行必有我师
hbhbhbhbhb1021(天外水火(我要多努力))似乎太偏激了
大家互相学习嘛 指出对方的错误可以指导对方学习新的知识
你刚才指出的错误就对我帮助很大 呵呵~~
function get(str) //从链接地址里提取出本文档名
{
alert(str.match(/\/([^\.\?/]*)(\.[^\?/]+)?(\?|$)/)[1])
}
get(location.href)
get("http://www.xxxx.com/xxx/xx1.htm")
get("http://www.xxxx.com/xxx/xx2.htm?text1=abcde&text2=fghij")
get("http://www.xxxx.com/xxx/xx3?text1=abcde&text2=fghij")
</script>
比如:http://www.xxxx.com/xxx/xxx.htm
/\/([^\?\/]+)(\?|$)/
是匹配开头为/但是中间不包含/并且结尾为$或者为?
满足这一条件的只有。。/xxx.htm
然后捕获xx.htm
alert(this.location.pathname.match(/(?!.*[\/\\])[^\?\#]*/));//取得index.asp