javascript - 求教:如何從頁(yè)面1鏈接到頁(yè)面2時(shí),使頁(yè)面2原本隱藏的div顯示?
問(wèn)題描述
如果純用js和html能做到嗎?想到的一個(gè)辦法是用頁(yè)面一的form傳參,頁(yè)面二來(lái)判斷參數(shù)決定p是否顯示。但是action傳過(guò)去的參數(shù)怎么被頁(yè)面2收到呢?
<!DOCTYPE html><html><head> <meta charset='utf-8'/> <title></title> </head><body><form action='index2.html#p'><input type='text' name='firstname' value=''><input type='submit' value='Submit'></form> </body></html>
請(qǐng)前輩們說(shuō)說(shuō),這個(gè)方法是否可行?具體怎么操作呢
問(wèn)題解答
回答1:獲取url參數(shù)
function GetQueryString(name){ var reg = new RegExp('(^|&)'+ name +'=([^&]*)(&|$)'); var r = window.location.search.substr(1).match(reg); if(r!=null)return unescape(r[2]); return null;} // 調(diào)用方法alert(GetQueryString('參數(shù)名1'));alert(GetQueryString('參數(shù)名2'));alert(GetQueryString('參數(shù)名3'));回答2:
還有一點(diǎn),CSS3的:target偽類選擇器也可以實(shí)現(xiàn)這個(gè)功能,主要是利用錨點(diǎn)
參考:http://css.doyoe.com/selector...
