century
BlogJava
首頁
新隨筆
聯系
聚合
管理
隨筆-3 評論-26 文章-41 trackbacks-0
js獲取URL中的參數值
/**/
/*
獲取URL中最后一項參數的值
*/
var
str
=
window.location.href;
//
alert(str);
var
es
=/
SouceID
=/
;
es.exec(str);
var
right
=
RegExp.rightContext;
//
alert(right);
//列子
<script language="javascript">
var str=window.location.href;
var es=/SouceID=/;
es.exec(str);
var right=RegExp.rightContext;
//alert(right);
switch(right){
case 'Din':
case 'Exh':
case 'Banks':
case 'Shop':
case 'Treat':
case 'Trip':
ChgTab('tab3','tabcontent3');
break;
case 'Air':
case 'Railway':
case 'Road':
case 'Subway':
ChgTab('tab2','tabcontent2');
break;
default:
ChgTab('tab1','tabcontent1');
}
</script>
//
以下是函數的寫法
function
GetParam()
{
var
url
=
document.location.href;
var
name
=
""
if
(url.indexOf(
"
=
"
)
>
0
)
{
name
=
url.substring(url.indexOf(
"
=
"
)
+
1
,url.length)
}
return
name;
}
/**/
/*
獲取指定的URL參數值
URL:http://www.aygfsteel.com/blog?name=bainian
參數:paramName URL參數
調用方法:getParam("name")
返回值:bainian
*/
//
1.
function
getParam(paramName)
{
paramValue
=
""
;
isFound
=
false
;
if
(
this
.location.search.indexOf(
"
?
"
)
==
0
&&
this
.location.search.indexOf(
"
=
"
)
>
1
)
{
arrSource
=
unescape(
this
.location.search).substring(
1
,
this
.location.search.length).split(
"
&
"
);
i
=
0
;
while
(i
<
arrSource.length
&&
!
isFound)
{
if
(arrSource[i].indexOf(
"
=
"
)
>
0
)
{
if
(arrSource[i].split(
"
=
"
)[
0
].toLowerCase()
==
paramName.toLowerCase())
{
paramValue
=
arrSource[i].split(
"
=
"
)[
1
];
isFound
=
true
;
}
}
i
++
;
}
}
return
paramValue;
}
//
2.
function
Request(sName)
{
/**/
/*
get last loc. of ?
right: find first loc. of sName
+2
retrieve value before next &
*/
var
sURL
=
new
String(window.location);
var
sURL
=
document.location.href;
var
iQMark
=
sURL.lastIndexOf('
?
');
var
iLensName
=
sName.length;
//
retrieve loc. of sName
var
iStart
=
sURL.indexOf('
?
'
+
sName
+
'
=
')
//
limitation 1
if
(iStart
==-
1
)
{
//
not found at start
iStart
=
sURL.indexOf('
&
'
+
sName
+
'
=
')
//
limitation 1
if
(iStart
==-
1
)
{
//
not found at end
return
0
;
//
not found
}
}
iStart
=
iStart
+
+
iLensName
+
2
;
var
iTemp
=
sURL.indexOf('
&
',iStart);
//
next pair start
if
(iTemp
==-
1
)
{
//
EOF
iTemp
=
sURL.length;
}
return
sURL.slice(iStart,iTemp ) ;
sURL
=
null
;
//
destroy String
}
posted on 2008-03-12 12:53
百年
閱讀(37317)
評論(5)
編輯
收藏
所屬分類:
Javascript Article
評論:
#
re: js獲取URL中的參數值[未登錄] 2012-10-09 23:04 |
lee
獲取url中的參數值
回復
更多評論
#
re: js獲取URL中的參數值[未登錄] 2013-02-09 08:43 |
匿名
感謝分享.
回復
更多評論
#
re: js獲取URL中的參數值 2013-08-06 10:58 |
afasfas
feafwaefeawfewaef
回復
更多評論
#
re: js獲取URL中的參數值 2013-08-06 10:58 |
afasfas
@afasfas
@afasfas
回復
更多評論
#
re: js獲取URL中的參數值
2014-08-26 14:11 |
趙元春
網址打不開
回復
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
單擊放回上頁的按鈕或使用window.history.go(-1)返回上頁的同時刷新"上頁"技術
js 提交表單
ShowModalDialog方法的參數傳遞
js獲取URL中的參數值
計算中英文混合字符串長度js函數
window.open和window.showModalDialog的用法詳細說明
常用于表單JS驗證
IE與FireFox下用程序觸發鼠標點擊事件不同的實現
Javascript中LenB的計算(ASP)
Javascript 實現的排序
<
2012年10月
>
日
一
二
三
四
五
六
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2008年7月 (2)
2006年8月 (1)
文章分類
.net(6)
Asp Article(14)
computer manage(2)
div+css(2)
Flash+XML/XML+Flash
Java Article(2)
Javascript Article(10)
Jsp Article(4)
Others(1)
文章檔案
2008年11月 (1)
2008年9月 (3)
2008年8月 (1)
2008年7月 (1)
2008年6月 (1)
2008年4月 (2)
2008年3月 (2)
2008年1月 (2)
2007年12月 (2)
2007年11月 (6)
2007年10月 (1)
2007年8月 (2)
2007年7月 (1)
2007年4月 (3)
2007年3月 (4)
2006年8月 (2)
2006年7月 (1)
2006年6月 (4)
相冊
My collection
收藏夾
JAVA程序員面試32問
CSS
ASP導出Excel數據的四種方法
CSS
Jsp
tomcat set
無憂視窗:51windows
用AspJpeg調整文字水印透明,生成圖片水印的效果
Draw dynamicdrive
Draw dynamic photo
My photo is very poor,so i must word hard!
Draw Flash
Draw Flash
Fade
Fade Images in photoshop
Flash+XML
Flash+XML
http://www.flashcom.com.cn/bbs/forumdisplay.php?f=3
Jacob
jacob
Search Website
程序員代碼搜索
Krugle - Code Search for Developers
Struts
Struts中用動態選擇的元素創建復選框
include some website design...
Studying English
Online Dictionary
Here,it is me study english
Translate on google
study
Text Link
\\Access Sql腳本編寫器!
Access to Sql 腳本編寫器
搜索
最新評論
1.?re: js獲取URL中的參數值
網址打不開
--趙元春
2.?re: js獲取URL中的參數值
feafwaefeawfewaef
--afasfas
3.?re: js獲取URL中的參數值
@afasfas
@afasfas
--afasfas
4.?re: js獲取URL中的參數值[未登錄]
感謝分享.
--匿名
5.?re: js獲取URL中的參數值[未登錄]
獲取url中的參數值
--lee
閱讀排行榜
1.?SP-service provider(341)
2.?為了學英語,轉載功夫熊貓一篇(278)
3.?什么是軟件外包?(258)
評論排行榜
1.?為了學英語,轉載功夫熊貓一篇(0)
2.?SP-service provider(0)
3.?什么是軟件外包?(0)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 百年
主站蜘蛛池模板:
张家界市
|
肃北
|
青岛市
|
韶山市
|
汉阴县
|
永定县
|
连南
|
全州县
|
武宁县
|
尚义县
|
博湖县
|
公安县
|
宝坻区
|
新巴尔虎右旗
|
颍上县
|
诏安县
|
分宜县
|
石阡县
|
卢湾区
|
深圳市
|
富平县
|
哈尔滨市
|
南城县
|
汉川市
|
津市市
|
林甸县
|
房山区
|
彭水
|
云林县
|
保山市
|
玉树县
|
镇雄县
|
平江县
|
元江
|
松潘县
|
隆回县
|
八宿县
|
合山市
|
新安县
|
吉木萨尔县
|
乌兰县
|