0

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>

このスクリプト自体を使用して、テーブルを表示/非表示にするにはどうすればよいでしょうか?

4

1 に答える 1

0

表示するテーブルの を取得idします。取得したら、使用document.getElementById('table').style.visibility = "hidden";して非表示にします。

表示するには:document.getElementById('table').style.visibility = "visible";

このスクリプトは最初にロードする必要があります!!

于 2012-08-27T09:50:36.643 に答える