点击input输入框弹出选择层
2013-05-20 21:16
295 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm9.aspx.cs" Inherits="CSDNproject.测试.WebForm9" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>点击input输入框弹出选择层(基于jquery) </title>
<%--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />--%>
<style type="text/css">
body{font-size:12px;}
.selectItemcont{padding:8px;}
#selectItem{background:#FFF;position:absolute;top:0px;left:center;border:1px solid #000;overflow:hidden;width:240px;z-index:1000;}
#selectItem2{background:#FFF;position:absolute;top:0px;left:center;border:1px solid #000;overflow:hidden;width:240px;z-index:1000;}
.selectItemtit{line-height:20px;height:20px;margin:1px;padding-left:12px;}
.bgc_ccc{background:#E88E22;}
.selectItemleft{float:left;margin:0px;padding:0px;font-size:12px;font-weight:bold;color:#fff;}
.selectItemright{float:right;cursor:pointer;color:#fff;}
.selectItemcls{clear:both;font-size:0px;height:0px;overflow:hidden;}
.selectItemhidden{display:none;}
</style>
<script src="../js/测试js/jquery-1.3.1.js" type="text/javascript"></script>
<script src="../js/测试js/jquery.bgiframe.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery.fn.selectCity = function (targetId) {
var _seft = this;
var targetId = $(targetId);
this.click(function () {
var A_top = $(this).offset().top + $(this).outerHeight(true); // 1
var A_left = $(this).offset().left;
targetId.bgiframe();
targetId.show().css({ "position": "absolute", "top": A_top + "px", "left": A_left + "px" });
});
targetId.find("#selectItemClose").click(function () {
targetId.hide();
});
targetId.find("#selectSub :checkbox").click(function () {
targetId.find(":checkbox").attr("checked", false);
$(this).attr("checked", true);
_seft.val($(this).val());
targetId.hide();
});
$(document).click(function (event) {
if (event.target.id != _seft.selector.substring(1)) {
targetId.hide();
}
});
targetId.click(function (e) {
e.stopPropagation(); // 2
});
return this;
}
$(function () {
//test1:
$("#address").selectCity("#selectItem");
//test2:
$("#address2").selectCity("#selectItem2");
});
</script>
</head>
<body>
</html>
<br/>
此弹出框特点:<br/>
1,弹出层出现在 文本框 下面.<br/>
2,点击弹出层内部 不关闭层,点击外面关闭弹出层.<br/>
3,ie6依然能遮住下拉框.<br/><br/>
地址选择一:<br/>
<input type="text" name="address" id="address" >
<br/><br/>
地址选择二:<br/>
<input type="text" name="address2" id="address2" size="20" >
<br/><br/><br/>
<div id="selectItem" class="selectItemhidden">
<div id="selectItemAd" class="selectItemtit bgc_ccc">
<h2 id="selectItemTitle" class="selectItemleft">常用标签</h2>
<div id="selectItemClose" class="selectItemright">关闭</div>
</div>
<div id="selectItemCount" class="selectItemcont">
<div id="selectSub">
<input type="checkbox" name="cr01" id="cr01" value="string"/><label for="cr01">string</label>
<input type="checkbox" name="cr02" id="cr02" value="cmd"/><label for="cr02">cmd</label>
<input type="checkbox" name="cr03" id="cr03" value=".net"/><label for="cr03">.net</label>
<input type="checkbox" name="cr09" id="cr09" value="asp.net"/><label for="cr09">asp.net</label>
</div>
</div>
</div>
<div id="selectItem2" class="selectItemhidden">
<div id="selectItemAd" class="selectItemtit bgc_ccc">
<h2 id="selectItemTitle" class="selectItemleft">请选择城市</h2>
<div id="selectItemClose" class="selectItemright">关闭</div>
</div>
<div id="selectItemCount" class="selectItemcont">
<div id="selectSub">
<input type="checkbox" name="cr04" id="cr04" value="北京1"/><label for="cr04">北京1</label>
<input type="checkbox" name="cr05" id="cr05" value="北京2"/><label for="cr05">北京2</label>
<input type="checkbox" name="cr06" id="cr06" value="北京3"/><label for="cr06">北京3</label>
<input type="checkbox" name="cr07" id="cr07" value="北京4"/><label for="cr07">北京4</label>
</div>
</div>
</div>
下面是效果图
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>点击input输入框弹出选择层(基于jquery) </title>
<%--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />--%>
<style type="text/css">
body{font-size:12px;}
.selectItemcont{padding:8px;}
#selectItem{background:#FFF;position:absolute;top:0px;left:center;border:1px solid #000;overflow:hidden;width:240px;z-index:1000;}
#selectItem2{background:#FFF;position:absolute;top:0px;left:center;border:1px solid #000;overflow:hidden;width:240px;z-index:1000;}
.selectItemtit{line-height:20px;height:20px;margin:1px;padding-left:12px;}
.bgc_ccc{background:#E88E22;}
.selectItemleft{float:left;margin:0px;padding:0px;font-size:12px;font-weight:bold;color:#fff;}
.selectItemright{float:right;cursor:pointer;color:#fff;}
.selectItemcls{clear:both;font-size:0px;height:0px;overflow:hidden;}
.selectItemhidden{display:none;}
</style>
<script src="../js/测试js/jquery-1.3.1.js" type="text/javascript"></script>
<script src="../js/测试js/jquery.bgiframe.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery.fn.selectCity = function (targetId) {
var _seft = this;
var targetId = $(targetId);
this.click(function () {
var A_top = $(this).offset().top + $(this).outerHeight(true); // 1
var A_left = $(this).offset().left;
targetId.bgiframe();
targetId.show().css({ "position": "absolute", "top": A_top + "px", "left": A_left + "px" });
});
targetId.find("#selectItemClose").click(function () {
targetId.hide();
});
targetId.find("#selectSub :checkbox").click(function () {
targetId.find(":checkbox").attr("checked", false);
$(this).attr("checked", true);
_seft.val($(this).val());
targetId.hide();
});
$(document).click(function (event) {
if (event.target.id != _seft.selector.substring(1)) {
targetId.hide();
}
});
targetId.click(function (e) {
e.stopPropagation(); // 2
});
return this;
}
$(function () {
//test1:
$("#address").selectCity("#selectItem");
//test2:
$("#address2").selectCity("#selectItem2");
});
</script>
</head>
<body>
</html>
<br/>
此弹出框特点:<br/>
1,弹出层出现在 文本框 下面.<br/>
2,点击弹出层内部 不关闭层,点击外面关闭弹出层.<br/>
3,ie6依然能遮住下拉框.<br/><br/>
地址选择一:<br/>
<input type="text" name="address" id="address" >
<br/><br/>
地址选择二:<br/>
<input type="text" name="address2" id="address2" size="20" >
<br/><br/><br/>
<div id="selectItem" class="selectItemhidden">
<div id="selectItemAd" class="selectItemtit bgc_ccc">
<h2 id="selectItemTitle" class="selectItemleft">常用标签</h2>
<div id="selectItemClose" class="selectItemright">关闭</div>
</div>
<div id="selectItemCount" class="selectItemcont">
<div id="selectSub">
<input type="checkbox" name="cr01" id="cr01" value="string"/><label for="cr01">string</label>
<input type="checkbox" name="cr02" id="cr02" value="cmd"/><label for="cr02">cmd</label>
<input type="checkbox" name="cr03" id="cr03" value=".net"/><label for="cr03">.net</label>
<input type="checkbox" name="cr09" id="cr09" value="asp.net"/><label for="cr09">asp.net</label>
</div>
</div>
</div>
<div id="selectItem2" class="selectItemhidden">
<div id="selectItemAd" class="selectItemtit bgc_ccc">
<h2 id="selectItemTitle" class="selectItemleft">请选择城市</h2>
<div id="selectItemClose" class="selectItemright">关闭</div>
</div>
<div id="selectItemCount" class="selectItemcont">
<div id="selectSub">
<input type="checkbox" name="cr04" id="cr04" value="北京1"/><label for="cr04">北京1</label>
<input type="checkbox" name="cr05" id="cr05" value="北京2"/><label for="cr05">北京2</label>
<input type="checkbox" name="cr06" id="cr06" value="北京3"/><label for="cr06">北京3</label>
<input type="checkbox" name="cr07" id="cr07" value="北京4"/><label for="cr07">北京4</label>
</div>
</div>
</div>
下面是效果图
相关文章推荐
- "点击input输入框弹出选择层"的实现(二)
- 点击input输入框弹出选择层
- "点击input输入框弹出选择层"的实现
- 利用javaScript实现点击输入框弹出窗体选择信息
- <转>Android开发使输入框点击弹出日期选择对话框的方法
- js 点击input弹出选择框
- Android开发使输入框点击弹出日期选择对话框的方法
- 不用点击file类型的input弹出文件选择对话框
- JS实现点击下拉菜单把选择的内容同步到input输入框内的实例
- asp.net 点击一个按钮弹出对话框选择文件然后选择文件完成之后就自动上传文件 input(file)
- Android WebView加载带有Input的输入框时点击无法弹出软键盘的问题解决
- android 实现点击输入框弹出日期选择对话框(DatePickerDialog)
- jquery实现input点击输入框弹出日期
- 点击文本输入框弹出日期选择对话框
- 移动端点击输入框 input被弹出键盘挡住
- javaScript实现点击输入框弹出窗体选择信息
- 利用javaScript实现点击输入框弹出窗体选择信息
- css的position在不同手机系统的兼容问题(点击input标签弹出输入框影响样式)
- 移动端中点击input弹出的键盘输入框会覆盖页面底部
- 解决input file按钮要点击两次才弹出选择文件窗口