嘿,我想在用户填写输入时显示表格。当输入填充时,javascript显示隐藏的元素
我所拥有的是:
在<head>
部分:
<script type="text/javascript">
//hide initially
$("table#mytable").hide();
// show function
function showit() {
$("table#mytable").show();
}
</script>
和表:
<table id="mytable"><tr><td>FOO</td><td>BAR</td></tr></table>
及以下(也许是很重要的)表形式:
<form action="foobar.php">
<input name="example" onselect="showit()" />
<input type="submit" value="Send" />
</form>
我认为onselect并不完美,但它应该在我的情况下做到这一点。
上面的代码根本不隐藏表格。我不知道我做错了什么。希望some1能找到一个错误 - 谢谢。
编辑
这里是解决方案:
head
:
<script type="text/javascript">
function show(id) {
document.getElementById(id).style.display = 'block';
}
</script>
,并在每个元素隐藏只需添加style="display: none;"
和编辑输入 - 增加onkeyup="show('id')
其中id是元素隐藏的ID例如#mytable
尝试和没有工作 – andrewpo
请参阅更新 –