0
<select style="height:25px;"class="textbox">
    <option selected>Select item</option>
    <option value="1" >Gold cad.</option>
    <option value="2">Gold rawa</option>
    <option value="3">Silver 9999</option>
    <option value="4">Silver chorsa</option>
</select>

我想通过在单击时用文本框替换选择框来在文本框中显示选择框元素

4

3 回答 3

1

参考这个LIVE DEMO

Javascript:

var dropDown = document.getElementById("dropdown")
dropDown.onchange = function() {
    var dropDownValue = this.options[this.selectedIndex];
    dropDown.style.display = 'none';

    var textBox = document.getElementById("textbox");
    textBox.style.display = 'block';
    textBox.value = dropDownValue.text;
};

HTML:

<select style="height:25px;" id="dropdown">     
    <option selected>Select item</option>     
    <option value="1" >Gold cad.</option>     
    <option value="2">Gold rawa</option>     
    <option value="3">Silver 9999</option>     
    <option value="4">Silver chorsa</option> 
</select>
<input type="text" id="textbox" class="inactive" /> 

CSS:

.inactive {
    display: none;
}
于 2012-06-21T04:54:12.753 回答
0

例如

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档&lt;/title>
<script type="text/javascript">
  function  toggle()
  {
      var div=document.getElementById("Show");
      if(div.style.display=="none")
      {
          div.style.display="block";
      }
      else

      {
          div.style.display="none";
      }
  }
  function changeText (value)
  {
      document.getElementById("text").value=value;
      toggle();
  }

</script>
</head>

<body>
<input id="text" type="text"  width="150px" height="20px" onfocus="toggle()" />
<div id="Show"   style="width:150px; display:none; border:1px solid red"    >
<div style="border-bottom:1px solid #03F" onclick="changeText('1')">Gold cad</div>
<div  style="border-bottom:1px solid #03F" onclick="changeText('2')">Gold rawa</div>
<div  style="border-bottom:1px solid #03F" onclick="changeText('3')">Silver 9999</div>
</div>

</body>
</html>

这是一个例子,即使它很糟糕。

于 2012-06-21T04:47:56.780 回答
0

这样的事情可以帮助你:

$('select.textbox').change(function(){
  $('<input>')
     .attr('name', $(this).attr('name'))
     .val($(this)
     .find('option:selected'))
     .insertAfter($(this).hide());
});
于 2012-06-21T04:28:01.740 回答