本来不知道如何获取服务器的控件的,这下知道可以这么做了,所以记录下来。。。。

<asp:ImageButton ID="alltime" ImageUrl="images/SmallPage/dsj.png"
runat="server" style="width: 13px; height: 11px;" />

<!--这是个小三角图片,我要实现的功能是点击这个小三角,

一个listbox就能显示出来,再点击一下小三角或者点击页面的其他地方,这个

listbox就隐藏了,可恶的是,我点击不是这个小三角的地方,listbox还是会莫名其妙的显示出来,页面也刷新了,不知道是为嘛,难道是服务器控件的缘故,亟待解决!-->

$(function () {

$(document).bind("click", function (event) {
 var e = event || window.event;
 var elm = e.srcElement || e.target;//当前点击的元素,elm.id当前点击的元素的ID

if (elm.id != "alltime" && elm.id != "lastPublic") {
$("#<%=list1.ClientID%>").css("display", "none");
$("#<%=list2.ClientID%>").css("display", "none");
}

if (elm.id == "alltime") {
$("#<%=list1.ClientID%>").css("display", "block");
$("#<%=list2.ClientID%>").css("display", "none");
}

if (elm.id == "lastPublic") {
$("#<%=list1.ClientID%>").css("display", "none");
$("#<%=list2.ClientID%>").css("display", "block");
}

}

<asp:ImageButton ID="alltime" ImageUrl="images/SmallPage/dsj.png"
runat="server" style="width: 13px; height: 11px;"/>

<asp:ListBox runat="server" ID="list1" AutoPostBack="true" Width="80" style="z-index:999; position:relative;margin-left:-65px; display:none;">
<asp:ListItem>一天</asp:ListItem>
<asp:ListItem>两天</asp:ListItem>
<asp:ListItem>一周</asp:ListItem>
<asp:ListItem>一个月</asp:ListItem>
<asp:ListItem>三个月</asp:ListItem>
</asp:ListBox>

<asp:ImageButton ID="lastPublic" runat="server" ImageUrl="images/SmallPage/dsj.png" style="width: 13px; height: 11px;" />

<asp:ListBox runat="server" ID="list2" AutoPostBack="true" Width="80" style="z-index:999; position:relative;margin-left:-65px; display:none;" >
<asp:ListItem Selected="True">发帖时间</asp:ListItem>
<asp:ListItem>回复/查看</asp:ListItem>
<asp:ListItem>查看</asp:ListItem>
<asp:ListItem>最后发表</asp:ListItem>
<asp:ListItem>热门</asp:ListItem>
</asp:ListBox>

之前小三角是用服务器控件ImageButton去做,所以总会刷新,现在我把小三角改为

<div style="width: 13px; height: 11px; background: url('images/SmallPage/dsj.png');" id="alltime">
</div>

<div style="width: 13px; height: 11px; background: url('images/SmallPage/dsj.png');" id="lastPublic">
</div>

总算是不会刷新了,而且jquery的部分也改为

<script type="text/javascript" src="JS/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(function () {

// $("#alltime").click(function () {
// $("#<%=list1.ClientID%>").css("display", "block");
// });

// $("#lastPublic").click(function () {
// $("#<%=list2.ClientID%>").css("display", "block");
// });
$(document).click(function (event) {
var e = event || window.event;
var elm = e.srcElement || e.target;
// if (elm.id != "alltime" || elm.id!="lastPublic") {
// $("#<%=list1.ClientID%>").css("display", "none");
// $("#<%=list2.ClientID%>").css("display", "none");
// }

if (elm.id == "alltime") {//点击该元素的时候,判断它是否已经显示,若隐藏,则显示,若显示,则隐藏
if ($("#<%=list1.ClientID%>").css("display") == "none") {
$("#<%=list1.ClientID%>").css("display", "block");
$("#<%=list2.ClientID%>").css("display", "none");
} else {
$("#<%=list1.ClientID%>").css("display", "none");
$("#<%=list2.ClientID%>").css("display", "none");
}
}

if (elm.id == "lastPublic") {
if ($("#<%=list2.ClientID%>").css("display") == "none") {
$("#<%=list1.ClientID%>").css("display", "none");
$("#<%=list2.ClientID%>").css("display", "block");
} else {
$("#<%=list1.ClientID%>").css("display", "none");
$("#<%=list2.ClientID%>").css("display", "none");
}
}

if (elm.id != "lastPublic") {
$("#<%=list2.ClientID%>").css("display", "none");
}

if (elm.id != "alltime") {
$("#<%=list1.ClientID%>").css("display", "none");
}

});
});
</script>

不仅是按钮做得不好,也由于jquery中的判断做得不好,所以才会导致想要实现的功能实现不了,现在终于好了,我可以去做其他的工作了!!^_^

jquery 点击按钮实现listbox的显示与隐藏,点击其他地方按钮外的地方,隐藏listbox的更多相关文章

  1. js进阶 12-15 jquery如何实现点击button显示列表,点击其它位置隐藏列表

    js进阶 12-15 jquery如何实现点击button显示列表,点击其它位置隐藏列表 一.总结 一句话总结:在button中阻止事件冒泡. 1.如何咋button中阻止事件冒泡(两种方法)? ev ...

  2. jquery实现点击显示,再点击隐藏

    //点击a标签,轮流显示和隐藏<div id="timo" style="background-color:red;height:50px;width:50px;& ...

  3. js 页面按钮提交后 创建显示loading div 操作完成后 再隐藏或删除 进度div

    预期效果: 1.点击Save按钮,创建及显示loading div框 2.Save操作完成后,再删除loading 及弹出提示结果 <html> <head> </hea ...

  4. jQuery将物体居中,并且转换显示和隐藏

    今天来给大家贴一段代码,代码的作用就是利用jQuery将物体居中,并且转换显示和隐藏: 首先建立一个div标签并且写好css样式,具体如下 然后我想要的效果是当我点击了button这个按钮,test可 ...

  5. td默认文字超出后显示..,点击tr时td文字显示完整

    做项目时,产品提的需求,table表格里面,每一列限制文字超出宽度后显示省略号,等点击td时,文字显示完整,今天整理了一下代码,积累一下 备注:1.邮箱和网址,在td里面不会自动换行,需要增加word ...

  6. 5.用JQuery实现选中select里面的option显示对应的div

    用JQuery实现选中select里面的option显示对应的div HTML: <select name=""  onchange="select(this)&q ...

  7. jQuery控制checkbox选中状态但是不显示选中

    问题描述:使用jQuery来控制checkbox的选中状态,但是第一次点击出现选中样式,之后点击可以看到checked的属性增加成功但是并没有选 中状态. 问题代码: function chooseA ...

  8. Vue - 实现双击显示编辑框;自动聚焦点击的显示框;点击编辑框外的地方,隐藏编辑框

    实现这三个功能的踩坑记录. 1. 需求 在Vue中,有一个input, 双击时编辑文本,点击该input节点外的其他地方,则取消编辑. 那么这里有三个要实现的地方 第一是双击显示编辑框. 第二是自动聚 ...

  9. jQuery实现打开网页自动弹出遮罩层或点击弹出遮罩层功能示例

    本文实例讲述了jQuery实现打开网页自动弹出遮罩层或点击弹出遮罩层功能.分享给大家供大家参考,具体如下: 弹出层:两种方式 一是打开网页就自动弹出层二是点击弹出 <!DOCTYPE html ...

  10. jquery easyui datebox 时间控件默认显示当前日期的实现方法

    jquery easyui datebox 时间控件默认显示当前日期的实现方法 直接class easyui-datebox后添加一个value="true"就可以

随机推荐

  1. node.js NPM 使用

    n=NPM是一个Node包管理和分发工具,已经成为了非官方的发布Node模块(包)的标准.有了NPM,可以很快的找到特定服务要使用的包,进行下载.安装以及管理已经安装的包.npms安装: 下载npm源 ...

  2. /var/cache/apt/archives/lock - open

    问题: E: 无法获得锁 /var/cache/apt/archives/lock - open (11 资源临时不可用)E: 无法锁定下载目录o rm /var/cache/apt/archives ...

  3. 利用PowerDesigner15在win7系统下对MySQL 进行反向project(二)

    利用PowerDesigner15在win7系统下对MySQL 进行反向project 1.打开PowerDesigner,建立新模型.选择Physical Data Model中的Physical ...

  4. leetCode 31.Next Permutation (下一个字典序排序) 解题思路和方法

    Next Permutation  Implement next permutation, which rearranges numbers into the lexicographically ne ...

  5. protobuf使用错误总结

    1>HelloWorldScene.obj : error LNK2019: 无法解析的外部符号 "public: virtual __thiscall LoginReqMessage ...

  6. Moss 几个编程技巧

    1.提升权限执行的代码 SPSecurity.RunWithElevatedPrivileges(delegate() { // 需要提升权限执行的代码 }); 应用场景:当前用户可能没有权限执行的操 ...

  7. JavaScript 中的面向对象的初步认识

    我在学习JS的面向对象编程的时候,总是有两个奇怪的问题. 第一个就是:面向对象在JS中很少用到... 可能是目前自己做的项目还是比较简单,前端方面的任务我几乎都是用面向过程的方式写的,所以就导致,我啃 ...

  8. unity读取Sqlite数据库

    using UnityEngine; using System.Collections; using Mono.Data.Sqlite; using System.Data; public enum ...

  9. Programming C#.Classes and Objects.只读字段

    只读字段 当字段声明中含有 readonly 修饰符时,该声明所引入的字段为只读字段.给只读字段的直接赋值只能作为声明的组成部分出现,或在同一类中的实例构造函数或静态构造函数中出现.(在这些上下文中, ...

  10. php7 install script

    ./configure --prefix=/home/admin/local/php7 --with-gd=/home/admin/local/libgd-2.1.1/ --with-jpeg-dir ...