注册 登录
编程论坛 JavaScript论坛

怎样用JS处理鼠标点击事件的一个问题?

gu_tong2008 发布于 2010-11-29 10:00, 552 次点击
有没有人帮我解决这样一个问题,代码如:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.part1{width:800px;height:400px;border:1px solid #11498a;margin:0 auto;}
.part2{width:800px;height:400px;margin:0 auto;}
</style>
</head>
<body>
    <div class="part1"></div>
    <div class="part2">
         <select name="aa" size="18">
          <option value="0">------------------------------------------------------------</option>
          <option value="1">------------------------------------------------------------</option>
      </select>      
     </div>
</body>
</html>

当我用鼠标点击part2中name="aa"的select选项时,其选项被选中,那么能不能实现此时当我用鼠标点击part1的任何位置的时候,name="aa"的列表中刚才被选中的选项不被选中呢?能否举个例子,把代码贴出来?


[ 本帖最后由 gu_tong2008 于 2010-11-29 10:01 编辑 ]
2 回复
#2
sclorg2010-11-29 10:38
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.part1{width:800px;height:400px;border:1px solid #11498a;margin:0 auto;}
.part2{width:800px;height:400px;margin:0 auto;}
</style>
</head>
<body>
    <div id='div1' class="part1"></div>
    <div class="part2">
         <select id="aa" size="18">
          <option value="0">------------------------------------------------------------</option>
          <option value="1">------------------------------------------------------------</option>
      </select>      
     </div>
</body>
<script>
var div = document.getElementById('div1');
var sel = document.getElementById('aa');
div.onclick=function(){sel.selectedIndex=-1 ;}
</script>
</html>
#3
gu_tong20082010-11-29 10:51
谢谢!
1