在javascript中将选择框更改为文本框 选择项 黄金cad。 黄金拉瓦 银9999 银索
我想在文本框中显示选择框元素,方法是在单击时将选择框替换为文本框。类似的内容可帮助您:在javascript中将选择框更改为文本框 选择项 黄金cad。 黄金拉瓦 银9999 银索,javascript,html,Javascript,Html,我想在文本框中显示选择框元素,方法是在单击时将选择框替换为文本框。类似的内容可帮助您: <select style="height:25px;"class="textbox"> <option selected>Select item</option> <option value="1" >Gold cad.</option> <option value="2">Gold rawa</optio
<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>
$('select.textbox').change(函数(){
$('')
.attr('name',$(this).attr('name'))
.val($(本)
.find('option:selected'))
.insertAfter($(this.hide());
});
例如
$('select.textbox').change(function(){
$('<input>')
.attr('name', $(this).attr('name'))
.val($(this)
.find('option:selected'))
.insertAfter($(this).hide());
});
无标题文档
函数切换()
{
var div=document.getElementById(“显示”);
如果(div.style.display==“无”)
{
div.style.display=“块”;
}
其他的
{
div.style.display=“无”;
}
}
函数changeText(值)
{
document.getElementById(“text”).value=value;
切换();
}
黄金cad
黄金拉瓦
银9999
这就是一个例子,即使它很糟糕。请参考此
Javascript:
HTML:
那么,如果用户不小心点击了错误的项目,他们会被卡住吗?那么通过键盘进行选择的用户呢?我想知道您为什么要这样做。我想你想说的是一个自动完成的文本框,就像你在facebook或谷歌搜索时得到的一样。
<!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>
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;
}