<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>
我想在文本框中显示选择框元素,方法是单击
上的文本框选择框答案 0 :(得分:1)
请参阅 LIVE DEMO
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;
};
<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" />
.inactive {
display: none;
}
答案 1 :(得分:0)
这样的事情可以帮助你:
$('select.textbox').change(function(){
$('<input>')
.attr('name', $(this).attr('name'))
.val($(this)
.find('option:selected'))
.insertAfter($(this).hide());
});
答案 2 :(得分: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>无标题文档</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>
这是一个例子,即便如此糟糕。