URL 매개 변수를 기반으로 표를 표시/숨기기를 원합니다. 이미이 같은 내 URL을URL 매개 변수에 따라 표를 표시/숨기기를 원합니다.
참고 : www.mydomainname.com?selecoption=1 & SELEC =
1 이제 SHOW/HIDE 테이블에 대한 나의 URL은 다음과 같이 될 것입니다 : WWW. mydomainname.com? selecoption=1 & selec = 1 & showid = 46
이전에 이미 사용했던 스크립트가 있습니다. 스크립트는 다음과 같습니다 :
<script type="text/javascript">
function getUrlVar(varName) { //returns empty string if variable name not found in URL
if (!varName) return ''; //no variable name specified. exit and return empty string
varName = varName.toLowerCase(); //convert to lowercase
var params = location.search; //get URL
if (params == '') return ''; //no variables at all. exit and return empty string
var vars = params.split('?')[1].split('&'); //get list of variable+value strings
if (vars instanceof String) { //is a string. i.e.: has no "&" separator; or only one variable
vars = [vars]; //put into array
}
for (var i = 0; i < vars.length; i++) { //check each variable
var varPair = vars[i].split('='); //split variable and its value
if (varPair instanceof Array) { //is an array. i.e.: has "=" separator
if (varPair[0].toLowerCase() == varName) { //same variable name?
return varPair[1]; //found variable. exit and return its value
} //else: check next variable, if any
} //else: is not an array. i.e.: invalid URL variable+value format. ignore it
}
return ''; //no matching variable found. exit and return empty string
}
function show() {
var value = getUrlVar('selecoption'); /get variable value
if (!value) return; //variable not found
if (parseInt(value) == NaN) return; //value is not a number
var sel = document.getElementById('form1').selecoption;
for (var i=0; i < sel.length; i++) {
if (sel.options[i].value == value) {
document.getElementById('form1').selecoption.value = value;
return;
}
}
}
</script>
이제이 스크립트 자체를 사용하여, 내가 어떻게/HIDE 테이블을 보일 수 있는가?
또한 HTML 코드를 공유하십시오. – Sajith
'.split()'메쏘드의 결과는 항상 배열이 될 것이고, 문자열 형이 아니고'String' 형 것도 아닙니다 – Bergi