我想根据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>
现在通过使用这个脚本本身,我该如何显示/隐藏表?
答案 0 :(得分:0)
获取要显示的表格的id
。完成后,使用document.getElementById('table').style.visibility = "hidden";
隐藏它。
要显示它:document.getElementById('table').style.visibility = "visible";
这个脚本应该在第一个加载!!