function showMe( ){
document.getElementById("kk").style.display = "block";
}
function closeMe( ){
document.getElementById("kk").style.display = "none";
}
function selectPlace( val ){
myform.chakan_caidan.value = val;
closeMe( );
}

function showMe1( ){
document.getElementById("kk3").style.display = "block";
}
function closeMe1( ){
document.getElementById("kk3").style.display = "none";
}
function selectPlace( val ){
myform.chakan_caidan.value = val;
closeMe( );
}
function showMe2( ){
document.getElementById("kk4").style.display = "block";
}
function closeMe2( ){
document.getElementById("kk4").style.display = "none";
}
function selectPlace( val ){
myform.chakan_caidan.value = val;
closeMe( );
}
这个是我弄的关闭div层,因为要用到多个,这样写太累了,
各位能不能帮帮忙,变的灵活简单些,

解决方案 »

  1.   


     funcion a(id,show){
    var el=document.getElementById(id);
    if(show) el.style.display ="block";
    else el.style.display ="none";
    }
    function selectPlace( val ){
    myform.chakan_caidan.value = val;
    a("kk",false);
    }
      

  2.   

    同时调用一个方法
    function controlMe(id, style){
          //id为所操作的元素,style为展示的样式
          document.getElementById(id).style.display = style;
    }
      

  3.   


    <div onclick = "shwoorcolse(this)"></div>
    function shwoorcolse(obj)
    {
      if (obj.style.display  == "block")
      {
         obj.style.display = = "none";
      }
      else
      {
        obj.style.display = = "block";
      }
    }
      

  4.   


    <div id="mydiv" style="width:100px; height:100px; background:#000; display:block"></div>
    <input type="button" value="测试"onclick="clickMe('mydiv')"/>
    <script type="text/javascript">
    function $(id){ return document.getElementById(id)}
    function clickMe(thisId){
    $(thisId).style.display = $(thisId).style.display == "block"?"none":"block";
    }
    </script>
      

  5.   

    <div id="mydiv" style="width:100px; height:100px; background:#000; display:block"></div>
    <input type="button" value="测试"onclick="clickMe('mydiv')"/>
    <script type="text/javascript">
    function $(id){ return document.getElementById(id)}
    function clickMe(thisId){
    $(thisId).style.display = $(thisId).style.display == "block"?"none":"block";
    }
    </script>