选择列表/菜单以显示def按钮

时间:2011-10-21 02:36:05

标签: javascript

问题:

我怎么能在这样的JavaScript中做...当我选择打开时,会出现按钮打开。

if selected = 'open'
  out='Open Button'
else if selected ='edit'
  out='Edit Button'
 else 
  out='Closed button'

Button = <input type="submit" name="Open" id="button" value="submit">
selected =  <select name="select" id="select">
            <option value="Open">Open</option>
            <option value="Edit">Edit</option>
            </select>

在那种情况下真的很棒...抱歉

1 个答案:

答案 0 :(得分:1)

当您提问时询问是否有帮助

<script type="text/javascript">
 function showOpenButton(n){

 if(n.value == "Open"){

 if(!document.getElementById("openBtn")){

   var oelm = document.getElementById('select');
   var btn = document.createElement("input");
   btn.type="submit";
   btn.value="Open Button";
   btn.id="openBtn"


   oelm.parentNode.appendChild(btn);
}
}

}
</script>


  <select name="select" id="select" onchange="showOpenButton(this)">
       <option value="">select one</option>
       <option value="Open">Open</option>
       <option value="Edit">Edit</option>
 </select>

//新功能可能有助于您新近仍然难以理解的要求

 function cBtn(n){

 var e = n.value;

 // if element placeholde exist remove it
 if(document.getElementById('div_btn_placeholder')){
   var tmp = document.getElementById('div_btn_placeholder'); // may need to set its css attribute display value to inline
  tmp.parentNode.removeChild(tmp);
  }

 var e = (n.selectedIndex==0) ? "Close" : n.value; //close or use other selected values on the button

 var d = document.createElement("div"); // easer to create a placeholde then can remove if defined
d.id="div_btn_placeholder";


var oelm = document.getElementById(n.id);
var btn = document.createElement("input");
btn.type="submit";
btn.value= e + " Button";
btn.id="btn" + e
btn.name=e;

oelm.parentNode.appendChild(d);

d.appendChild(btn)

}


function showOpenButton(n){

switch (n.value){
case "Open":cBtn(n); break;
case "Edit":cBtn(n); break;
default:cBtn(n);
}
}