如何显示由输入值定义的div
?
例如,如果我在输入字段dress
中输入#showme
,则会显示。
<form>
<input type="text" id="desc" value="" onKeyUp="myFunction()"/>
<div id="showme">
<input type="text" value="" />
<input type="text" value="" />
</div>
我试过这个,但遗憾的是没有工作
<script language="javascript" type="text/javascript">
function myFunction()
{
var input = document.getElementById('desc')
var div = document.getElementById('showme');
div.innerHTML = div.innerHTML + input.value;
}
</script>
答案 0 :(得分:1)
答案 1 :(得分:1)
您可以执行类似
的操作
function myFunction(el) {
var div = document.getElementById('showme');
var descval = document.getElementById('descval');
descval.innerHTML = el.value;
div.style.display = el.value == 'dress' ? 'block' : 'none';
}
&#13;
#showme {
display: none;
}
&#13;
<form>
<input type="text" id="desc" value="" onKeyUp="myFunction(this)" />
<div id="showme">
<input type="text" value="" />
<input type="text" value="" />
<!-- a span is used here so that there wouldn't be multiple appends -->
<span id="descval"></span>
</div>
</form>
&#13;