如何做字符串提取?

2ndboy 2003-02-25 05:29:20
比如字符串为
http://www.sohu.com?name=123
怎么把
name=123
提取出来?
...全文
53 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
2ndboy 2003-02-26
  • 打赏
  • 举报
回复
非常感谢各位!已经可以了,谁能告诉我为什么改成var foo=location.href就可以了?
muddledman 2003-02-25
  • 打赏
  • 举报
回复
up
烂笔头Danky 2003-02-25
  • 打赏
  • 举报
回复
将var foo=location改成var foo=location.href
2ndboy 2003-02-25
  • 打赏
  • 举报
回复
<script language="JavaScript">
{
var foo=location;
var i;
for(i=0;i< foo.length-1; i++)
{
if(foo.charAt(i) =='?'){break;}
}
var ss = foo.substring(i+1,foo.length);
this.document.writeln(ss);
}
</script>
我这样写为什么会出现错误?
因为location不是String对象吗?
aproc 2003-02-25
  • 打赏
  • 举报
回复
var nata = "http://www.sohu.com?name=123"
for (var i=0;i< nata.length-1;i++)
{
if(nata.charAt(i) =="?"){break;}
}
var ss = nata.substring(i+1,nata.length-1)
zjj2002 2003-02-25
  • 打赏
  • 举报
回复
var aa='http://www.sohu.com?name=123';
aa.split('_')[1];
meizz 2003-02-25
  • 打赏
  • 举报
回复
window.location.search url中?之后的信息
用这个方法你可以得到 ?name=123
你再修剪一下就OK了.
qiushuiwuhen 2003-02-25
  • 打赏
  • 举报
回复
location.search.substr(1)

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧