多标签分页怎样定位到本页面
由于工作需要,同一个页面有两个标签,可以点击切换,但所有ID都是指向本页面的,但又因为一刷新,又会定位到原始状态,因此只能做一个折中的方案:加变量值。以此变量来确定是那个标签。以前也有人说过#n的做法,但没有时间研究,但原理都是一样的。
<script type="text/javascript" language="javascript">
/* 此函数用于定位标签 */
function autoexec() {
var url = document.URL;
var pm = GetUrlParam(url,"x");
if(pm == 1) {
document.getElementById("s1").className = "s1";
document.getElementById("s2").className="s2";
document.getElementById("s1").style.borderRight="none";
document.getElementById("class1").style.display="block";
document.getElementById("class2").style.display="none";
}else if(pm == 2) {
document.getElementById("s1").className="s2";
document.getElementById("s2").className="s1";
document.getElementById("class1").style.display="none";
document.getElementById("class2").style.display="block";
}else {
document.getElementById("s1").className = "s1";
document.getElementById("s2").className="s2";
document.getElementById("s1").style.borderRight="none";
document.getElementById("class1").style.display="block";
document.getElementById("class2").style.display="none";
}
}
/* 此函数取得URL中的值 */
function GetUrlParam(url,paramName) {
var oRegex = new RegExp ( '[\?&]' + paramName + '=([^&]+)','i');
var oMatch = oRegex.exec(url);
if ( oMatch && oMatch.length > 1)
return oMatch[1];
else
return '';
}
</script>
<script type="text/javascript" language="javascript">
/* 此函数用于定位标签 */
function autoexec() {
var url = document.URL;
var pm = GetUrlParam(url,"x");
if(pm == 1) {
document.getElementById("s1").className = "s1";
document.getElementById("s2").className="s2";
document.getElementById("s1").style.borderRight="none";
document.getElementById("class1").style.display="block";
document.getElementById("class2").style.display="none";
}else if(pm == 2) {
document.getElementById("s1").className="s2";
document.getElementById("s2").className="s1";
document.getElementById("class1").style.display="none";
document.getElementById("class2").style.display="block";
}else {
document.getElementById("s1").className = "s1";
document.getElementById("s2").className="s2";
document.getElementById("s1").style.borderRight="none";
document.getElementById("class1").style.display="block";
document.getElementById("class2").style.display="none";
}
}
/* 此函数取得URL中的值 */
function GetUrlParam(url,paramName) {
var oRegex = new RegExp ( '[\?&]' + paramName + '=([^&]+)','i');
var oMatch = oRegex.exec(url);
if ( oMatch && oMatch.length > 1)
return oMatch[1];
else
return '';
}
</script>