----如何控制select在失去焦点时不显示-----

studyliang 2004-04-05 01:27:57
页面中有textarea和select,问题是如果我不从select中选择数据,select就不会消失,我想当我按下"<"时,弹出select框,而我不从里面选择数据,当我自己写数据时,怎样让select消失啊??????我用的方法是当按下"<"时,使select获得焦点,当textarea再次获得焦点时,select消失.我用下面的方法为什么不行!!!请指教!!!!
<div id="layertxt" onFocus="unShow()">
function unShow(){
if (document.getElementById(textarea).focus)
document.getElementById('layerTextarea').style.display='none';
}
...全文
838 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ice_berg16 2004-04-05
  • 打赏
  • 举报
回复
<div id="layertxt" style="position:absolute; left:24px; top:-4px; width:319px; height:81px; z-index:1; visibility: visible;">
<textarea id="te1" rows="10" cols="50" style="overflow:auto" onfocus="unShow()">
</textarea>
</div>
<div id="layerSel" style="position:absolute;left:20px;top:166px;width:91px;height:44px;z-index:2;">
<select name="select" size=3 id="sel" style="width:100">
<option>aaa</option>
</select>
</div>
<script language="javascript">
function unShow()
{
document.all.layerSel.style.display = "none";
}
</script>
kisslan 2004-04-05
  • 打赏
  • 举报
回复
studyliang 试试这个怎么样?把select的onchange事件换成了onclick事件,不会出现选过的值再次选中不能触发事件的问题
<div id="layertxt" style="position=absolute;left:50px;top:50;width=400;height=300;Z-index=1">
<textarea id=te1 rows="23" cols="100" style="overflow:auto" onfocus="unShow()"></textarea>
</div>
<div id="layerSel" style="position=absolute;left:50px;top:50;width=50;height=50;Z-index=2;display='none'">
<select id="sel"size=3 style="width:100" onclick="addTag(this.options[selectedIndex].value)">
<option value="1111">1111</option>
<option value="2222">2222</option>
<option value="3333">3333</option>
</select>
</div>
<button onclick="layerSel.style.display='';document.all.sel.focus()">显示select框</button>
<script language="JavaScript">
<!--
function addTag(val)
{
document.all.te1.value = document.all.te1.value+val;
layerSel.style.display='none';
}
function unShow()
{
layerSel.style.display='none';
}
//-->
</script>
studyliang 2004-04-05
  • 打赏
  • 举报
回复
快帮忙啊
studyliang 2004-04-05
  • 打赏
  • 举报
回复
请问如何在textarea获得焦点或者其文本发生改变时,sel不显示!!!
<div id="layertxt" style="position=absolute;left:50px;top:50;width=400;height=300;Z-index=1">
<textarea id=te1 rows="23" cols="100" style="overflow:auto" onfocus="Unshow();"></textarea>
</div>
<div id="layerSel" style="position=absolute;left:50px;top:50;width=50;height=50;Z-index=2;display='none'">
<select id="sel"size=3 style="width=100">
<options>aaa</options>
</select>
function unShow()
{

layerSel.style.display = "none";
}
心云意水 2004-04-05
  • 打赏
  • 举报
回复
按下"<"时
=>
"<"是什么啊?按钮?onclick="selectId.style.display=''"
xlever 2004-04-05
  • 打赏
  • 举报
回复
如果“layerTextarea”是个DIV的ID,可以这样用:
function OnHideSelect()
{
layerTextarea.style.visibility = "hidden";
layerTextarea.style.display = "none";
}
<textarea id=textarea onfocus="OnHideSelect();"></textarea>

display属性不是设置显示与否的属性,此处对本身已是块级元素的DIV似乎作用不大。
心云意水 2004-04-05
  • 打赏
  • 举报
回复
<textarea onfocus="selectId.style.display='none'"></textarea>

87,992

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧