我現在url鏈接有一個引數,例如xxx.php?lx=內容1,內容2,內容3
然后我現在頁面有x個表單。。。想讓上面的值在打開頁面時自動填寫到表單去。
<input type="text" name="shui_1" id="shui_1" size="20">
<input type="text" name="shui_2" id="shui_2" size="20">
<input type="text" name="shui_3" id="shui_3" size="20">
<input type="text" name="shui_4" id="shui_4" size="20">
。。。。。。以此類推。。。
然后上面lx的值可以分別自動填寫到下面前3個表單。。。
js要如何弄?搞了好久弄不出,求高手。。。
uj5u.com熱心網友回復:
js獲取 url?后面的引數取值var url = location.search; //獲取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
console.log(theRequest);
uj5u.com熱心網友回復:
你好,測驗后不行了,不知道是哪里有問題,能否給下完整一些代碼,學習下!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/116949.html
標籤:JavaScript
