严格的来说,JS是不接受客户端提交的数据的,用JS获取提交参数的方法,也是用正则对url进行分析,然后进行参数的获取,大的方法,可以分为以下几种。
方法一:

1
2
3
4
5
6
7
8
9
10
11
12
13
<span style="color: #339933"><</span>script. <span style="color: #660066">type</span><span style="color: #339933">=</span><span style="color: #3366CC">"text/javascript"</span><span style="color: #339933">></span>
<span style="color: #339933"><!--</span>
String.<span style="color: #660066">prototype</span>.<span style="color: #660066">getQuery</span> <span style="color: #339933">=</span> <span style="color: #003366;font-weight: bold">function</span><span style="color: #009900">(</span><span style="color: #000066">name</span><span style="color: #009900">)</span> <span style="color: #009900">{</span>
  <span style="color: #003366;font-weight: bold">var</span> reg <span style="color: #339933">=</span> <span style="color: #003366;font-weight: bold">new</span> RegExp<span style="color: #009900">(</span><span style="color: #3366CC">"(^|&)"</span><span style="color: #339933">+</span> <span style="color: #000066">name</span> <span style="color: #339933">+</span><span style="color: #3366CC">"=([^&]*)(&|$)"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
  <span style="color: #003366;font-weight: bold">var</span> r <span style="color: #339933">=</span> <span style="color: #000066;font-weight: bold">this</span>.<span style="color: #660066">substr</span><span style="color: #009900">(</span><span style="color: #000066;font-weight: bold">this</span>.<span style="color: #660066">indexOf</span><span style="color: #009900">(</span><span style="color: #3366CC">"<span style="color: #000099;font-weight: bold">\?</span>"</span><span style="color: #009900">)</span><span style="color: #339933">+</span><span style="color: #CC0000">1</span><span style="color: #009900">)</span>.<span style="color: #660066">match</span><span style="color: #009900">(</span>reg<span style="color: #009900">)</span><span style="color: #339933">;</span>
  <span style="color: #000066;font-weight: bold">if</span> <span style="color: #009900">(</span>r<span style="color: #339933">!=</span><span style="color: #003366;font-weight: bold">null</span><span style="color: #009900">)</span> <span style="color: #000066;font-weight: bold">return</span> unescape<span style="color: #009900">(</span>r<span style="color: #009900">[</span><span style="color: #CC0000">2</span><span style="color: #009900">]</span><span style="color: #009900">)</span><span style="color: #339933">;</span> <span style="color: #000066;font-weight: bold">return</span> <span style="color: #003366;font-weight: bold">null</span><span style="color: #339933">;</span>
<span style="color: #009900">}</span>
<span style="color: #003366;font-weight: bold">var</span> strHref <span style="color: #339933">=</span> <span style="color: #3366CC">"www.chhua.com/index.htm?a=aaa&b=bbb&c=ccc"</span><span style="color: #339933">;</span>
<span style="color: #000066">alert</span><span style="color: #009900">(</span>strHref.<span style="color: #660066">getQuery</span><span style="color: #009900">(</span><span style="color: #3366CC">"a"</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066">alert</span><span style="color: #009900">(</span>strHref.<span style="color: #660066">getQuery</span><span style="color: #009900">(</span><span style="color: #3366CC">"b"</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066">alert</span><span style="color: #009900">(</span>strHref.<span style="color: #660066">getQuery</span><span style="color: #009900">(</span><span style="color: #3366CC">"c"</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #006600;font-style: italic">//--></span>
<span style="color: #339933"></</span>script<span style="color: #339933">></span>

方法二:

1
2
3
4
5
6
7
8
9
10
11
12
<span style="color: #339933"><</span>script. <span style="color: #660066">type</span><span style="color: #339933">=</span><span style="color: #3366CC">"text/javascript"</span><span style="color: #339933">></span>
<span style="color: #003366;font-weight: bold">function</span> getUrlPara<span style="color: #009900">(</span>paraName<span style="color: #009900">)</span><span style="color: #009900">{</span>
<span style="color: #003366;font-weight: bold">var</span> sUrl <span style="color: #339933">=</span> location.<span style="color: #660066">href</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> sReg <span style="color: #339933">=</span> <span style="color: #3366CC">"(?:<span style="color: #000099;font-weight: bold">\\</span>?|&){1}"</span><span style="color: #339933">+</span>paraName<span style="color: #339933">+</span><span style="color: #3366CC">"=([^&]*)"</span>
<span style="color: #003366;font-weight: bold">var</span> re<span style="color: #339933">=</span><span style="color: #003366;font-weight: bold">new</span> RegExp<span style="color: #009900">(</span>sReg<span style="color: #339933">,</span><span style="color: #3366CC">"gi"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
re.<span style="color: #660066">exec</span><span style="color: #009900">(</span>sUrl<span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066;font-weight: bold">return</span> RegExp.$<span style="color: #CC0000">1</span><span style="color: #339933">;</span>
<span style="color: #009900">}</span>
<span style="color: #006600;font-style: italic">//应用实例:test_para.html?a=11&b=22&c=33</span>
<span style="color: #000066">alert</span><span style="color: #009900">(</span>getUrlPara<span style="color: #009900">(</span><span style="color: #3366CC">"a"</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066">alert</span><span style="color: #009900">(</span>getUrlPara<span style="color: #009900">(</span><span style="color: #3366CC">"b"</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #339933"></</span>script<span style="color: #339933">></span>

方法三:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<span style="color: #339933"><</span>script. <span style="color: #660066">type</span><span style="color: #339933">=</span><span style="color: #3366CC">"text/javascript"</span><span style="color: #339933">></span>
<span style="color: #339933"><!--</span>
<span style="color: #003366;font-weight: bold">function</span> Request<span style="color: #009900">(</span>strName<span style="color: #009900">)</span><span style="color: #009900">{</span>
<span style="color: #003366;font-weight: bold">var</span> strHref <span style="color: #339933">=</span> <span style="color: #3366CC">"www.chhua.com/index.htm?a=aaa&b=bbb&c=ccc"</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> intPos <span style="color: #339933">=</span> strHref.<span style="color: #660066">indexOf</span><span style="color: #009900">(</span><span style="color: #3366CC">"?"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> strRight <span style="color: #339933">=</span> strHref.<span style="color: #660066">substr</span><span style="color: #009900">(</span>intPos <span style="color: #339933">+</span> <span style="color: #CC0000">1</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> arrTmp <span style="color: #339933">=</span> strRight.<span style="color: #660066">split</span><span style="color: #009900">(</span><span style="color: #3366CC">"&"</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066;font-weight: bold">for</span><span style="color: #009900">(</span><span style="color: #003366;font-weight: bold">var</span> i <span style="color: #339933">=</span> <span style="color: #CC0000">0</span><span style="color: #339933">;</span> i <span style="color: #339933"><</span> arrTmp.<span style="color: #660066">length</span><span style="color: #339933">;</span> i<span style="color: #339933">++</span><span style="color: #009900">)</span> <span style="color: #009900">{</span>
<span style="color: #003366;font-weight: bold">var</span> arrTemp <span style="color: #339933">=</span> arrTmp<span style="color: #009900">[</span>i<span style="color: #009900">]</span>.<span style="color: #660066">split</span><span style="color: #009900">(</span><span style="color: #3366CC">"="</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066;font-weight: bold">if</span><span style="color: #009900">(</span>arrTemp<span style="color: #009900">[</span><span style="color: #CC0000">0</span><span style="color: #009900">]</span>.<span style="color: #660066">toUpperCase</span><span style="color: #009900">(</span><span style="color: #009900">)</span> <span style="color: #339933">==</span> strName.<span style="color: #660066">toUpperCase</span><span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #009900">)</span> <span style="color: #000066;font-weight: bold">return</span> arrTemp<span style="color: #009900">[</span><span style="color: #CC0000">1</span><span style="color: #009900">]</span><span style="color: #339933">;</span>
<span style="color: #009900">}</span>
<span style="color: #000066;font-weight: bold">return</span> <span style="color: #3366CC">""</span><span style="color: #339933">;</span>
<span style="color: #009900">}</span>
<span style="color: #000066">alert</span><span style="color: #009900">(</span>Request<span style="color: #009900">(</span><span style="color: #3366CC">"a"</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066">alert</span><span style="color: #009900">(</span>Request<span style="color: #009900">(</span><span style="color: #3366CC">"b"</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066">alert</span><span style="color: #009900">(</span>Request<span style="color: #009900">(</span><span style="color: #3366CC">"c"</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #006600;font-style: italic">//--></span>
<span style="color: #339933"></</span>script<span style="color: #339933">></span>

呵呵,问题解决了吧。