我正嘗試使用通過按下空白下拉菜單來切換的div來創建多選下拉的錯覺。它工作正常,但我希望能夠在div外部單擊時隱藏它。我該怎麼做呢?我使用下面的代碼:通過jQuery隱藏div上的模糊
<script src="../js/jqGlobal.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".testColor").click(function() {
$("#exampleDiv").toggle();
});
$("#exampleDiv").blur(function() {
$("#exampleDiv").toggle();
});
});
</script>
<style type="text/css">
#exampleDiv
{
position: absolute;
top:22px;
left: 0px;
width:198px;
height:150px;
overflow-y: scroll;
overflow-x: hidden;
border: 1px solid #7F9DB9;
display: none;
}
</style>
<div style="position:relative;">
<asp:DropDownList ID="DropDownList1" runat="server" Width="200" class="testColor">
</asp:DropDownList>
<div id="exampleDiv">
<asp:CheckBox ID="CheckBox2" runat="server" />
<br />
<asp:CheckBox ID="CheckBox3" runat="server" />
<br />
<asp:CheckBox ID="CheckBox4" runat="server" />
<br />
<asp:CheckBox ID="CheckBox5" runat="server" />
<br />
<asp:CheckBox ID="CheckBox6" runat="server" />
<br />
<asp:CheckBox ID="CheckBox7" runat="server" />
<br />
<asp:CheckBox ID="CheckBox8" runat="server" />
<br />
<asp:CheckBox ID="CheckBox9" runat="server" />
<br />
<asp:CheckBox ID="CheckBox10" runat="server" />
<br />
<asp:CheckBox ID="CheckBox11" runat="server" />
<br />
<asp:CheckBox ID="CheckBox12" runat="server" />
<br />
</div>
</div>
爲jquery點擊外部和其他有趣的事件:http://benalman.com/projects/jquery-outside-events-plugin/ – biziclop