0

我想根据 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>

现在通过使用这个脚本本身,我怎样才能显示/隐藏表格?

4

1 回答 1

0

获取id要显示的表格。一旦你有了它,用它document.getElementById('table').style.visibility = "hidden";来隐藏它。

要显示它:document.getElementById('table').style.visibility = "visible";

该脚本应首先加载!

于 2012-08-27T09:50:36.643 回答