日期:2014-05-16 浏览次数:20480 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="../jquery/jquery-1.5.2.min.js" type="text/javascript"></script> <script type="text/javascript"> //纯js版 window.onload = function () { var selBloodType = document.getElementById("selBloodType"); //$("#selBloodType"); var txtBloodType = document.getElementById("txtBloodType"); //$("#txtBloodType"); //显示血型下拉框 txtBloodType.onclick = function () { selBloodType.style.display = ""; } //血型下拉框选择项改变时 selBloodType.onchange = function () { txtBloodType.value = selBloodType.options[selBloodType.selectedIndex].value; ; selBloodType.style.display = "none"; } } </script> </head> <body> <div> <input type="text" id="txtBloodType" style="width: 100px" /> <div> <!-- 这里的select 要使用multiple模式 否则无法自动展开--> <select id="selBloodType" style="display: none; width: 100px" multiple="multiple" size="4"> <option value="A">A</option> <option value="B">B</option> <option value="AV">AV</option> <option value="H1">H1</option> <option value="H2">H2</option> </select> </div> </div> </body> </html>
------解决方案--------------------
这样?
<script> function createSelect() { var mySelect = document.createElement("select"); mySelect.id = "mySelect"; mySelect.onchange=function(){document.getElementById("blood").value=this.value} document.body.appendChild(mySelect); addOption(); } function addOption() { var obj=document.getElementById('mySelect'); obj.options[obj.options.length] = new Option("-请选择血型-","-1"); obj.options[obj.options.length] = new Option("B型","B型"); obj.options[obj.options.length] = new