Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将参数传递给函数_Javascript_Function_Arguments - Fatal编程技术网

Javascript 将参数传递给函数

Javascript 将参数传递给函数,javascript,function,arguments,Javascript,Function,Arguments,非常简单,我想在我的页面上多次使用下面的代码来处理一些“框”,那么当调用隐藏(box1ID)将隐藏box1ID等等时,如何传递参数 function conceal() { if(document.getElementById('box1ID').style.display=='block') { document.getElementById('box1ID').style.display='none'; } re

非常简单,我想在我的页面上多次使用下面的代码来处理一些“框”,那么当调用隐藏(box1ID)将隐藏box1ID等等时,如何传递参数

function conceal() {      
        if(document.getElementById('box1ID').style.display=='block') {
          document.getElementById('box1ID').style.display='none';
        }
        return false;
    }  

function show() {
    if(document.getElementById('box1ID').style.display=='none') {
      document.getElementById('box1ID').style.display='block';
    }
    return false;
}

这很简单,只需写下并包含它

    function conceal(element) {      
        if(document.getElementById(element).style.display=='block') {
          document.getElementById(element).style.display='none';
        }
        return false;
    }  

    function show(element) {
        if(document.getElementById(element).style.display=='none') {
          document.getElementById(element).style.display='block';
        }
    return false;
    }

Call it like so:
conceal('box1ID');

这很简单,只需写下并包含它

    function conceal(element) {      
        if(document.getElementById(element).style.display=='block') {
          document.getElementById(element).style.display='none';
        }
        return false;
    }  

    function show(element) {
        if(document.getElementById(element).style.display=='none') {
          document.getElementById(element).style.display='block';
        }
    return false;
    }

Call it like so:
conceal('box1ID');
你是说像这样

function conceal(boxID) {      
    if(document.getElementById(boxID).style.display=='block') {
      document.getElementById(box1ID).style.display='none';
    }
    return false;
}  
function conceal(boxId) {      
        if(document.getElementById(boxId).style.display=='block') {
          document.getElementById(boxId).style.display='none';
        }
        return false;
    }  

function show(boxId) {
    if(document.getElementById(boxId).style.display=='none') {
      document.getElementById(boxId).style.display='block';
    }
    return false;
}




show('box1ID');
conceal('box1ID');

你是说像这样

function conceal(boxID) {      
    if(document.getElementById(boxID).style.display=='block') {
      document.getElementById(box1ID).style.display='none';
    }
    return false;
}  
function conceal(boxId) {      
        if(document.getElementById(boxId).style.display=='block') {
          document.getElementById(boxId).style.display='none';
        }
        return false;
    }  

function show(boxId) {
    if(document.getElementById(boxId).style.display=='none') {
      document.getElementById(boxId).style.display='block';
    }
    return false;
}




show('box1ID');
conceal('box1ID');


我不知道你需要什么。是这样的吗

function conceal(boxID) {      
    if(document.getElementById(boxID).style.display=='block') {
      document.getElementById(box1ID).style.display='none';
    }
    return false;
}  
function conceal(boxId) {      
        if(document.getElementById(boxId).style.display=='block') {
          document.getElementById(boxId).style.display='none';
        }
        return false;
    }  

function show(boxId) {
    if(document.getElementById(boxId).style.display=='none') {
      document.getElementById(boxId).style.display='block';
    }
    return false;
}




show('box1ID');
conceal('box1ID');

我不知道你需要什么。是这样的吗

function conceal(boxID) {      
    if(document.getElementById(boxID).style.display=='block') {
      document.getElementById(box1ID).style.display='none';
    }
    return false;
}  
function conceal(boxId) {      
        if(document.getElementById(boxId).style.display=='block') {
          document.getElementById(boxId).style.display='none';
        }
        return false;
    }  

function show(boxId) {
    if(document.getElementById(boxId).style.display=='none') {
      document.getElementById(boxId).style.display='block';
    }
    return false;
}




show('box1ID');
conceal('box1ID');
这里我保存了一些代码

function showhide(id,show) {      
  document.getElementById(id).style.display=show?'block':'none';
  return false;
}  
内联用法(由于返回false,我假设您使用内联用法)

内联用法(由于返回false,我假设您使用内联用法)


这里我保存了一些代码

function showhide(id,show) {      
  document.getElementById(id).style.display=show?'block':'none';
  return false;
}  
内联用法(由于返回false,我假设您使用内联用法)

内联用法(由于返回false,我假设您使用内联用法)



如果您要问如何将参数传递给函数,这是非常基本的。这是我希望你在阅读入门教程/书籍时会学到的东西。我误解你的问题了吗?如果你问的是如何将参数传递给函数,这是非常基本的。这是我希望你在阅读入门教程/书籍时会学到的东西。我是否误解了你的问题?