又未jQuery的:
創建window.location.getParameter()
功能(請參閱從Anatoly Mironovhere),則:
<select name='elements' id='elements' onChange='window.location="yoururl.html?elements=" + this.selectedIndex;'>
<option value='water'>Water</option>
<option value='fire'>Fire</option>
<option value='air'>Air</option>
</select>
<script type="text/javascript">
els = document.getElementById('elements');
selIndex = window.location.getParameter('elements') || 0;
els[selIndex].selected = true;
</script>
爲便於參照,我下重現阿納託利的優秀.getParameter
功能:
window.location.getParameter = function(key) {
function parseParams() {
var params = {},
e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = window.location.search.substring(1);
while (e = r.exec(q))
params[d(e[1])] = d(e[2]);
return params;
}
if (!this.queryStringParams)
this.queryStringParams = parseParams();
return this.queryStringParams[key];
};
是否有任何理由需要整頁刷新?爲什麼不簡單地顯示/隱藏/填充異步調用...? – balexandre
我想翻譯整個頁面的內容到另一種語言,所以是的,我想整個頁面刷新 – user765368