jquery input选择弹框

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="jquery.plugin.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.plugin.css" />
<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);
            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();
        });

        return this;
    };

    $(function() {
        $("#address").selectCity("#selectItem");
        $("#address2").selectCity("#selectItem2");
    });
</script>
</head>
<body>

    <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" name="address" id="address" size="33"><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="北京1" />
                <label for="cr01">北京1</label>
                <input type="checkbox" name="cr02" id="cr02" value="北京2" />
                <label for="cr02">北京2</label>
                <input type="checkbox" name="cr03" id="cr03" value="北京3" />
                <label for="cr03">北京3</label>
                <input type="checkbox" name="cr09" id="cr09" value="北京4" />
                <label for="cr09">北京4</label>
                <input type="checkbox" name="cr09" id="cr09" value="北京4" />
                <label for="cr09">北京4</label>
                <input type="checkbox" name="cr09" id="cr09" value="北京4" />
                <label for="cr09">北京4</label>
                <input type="checkbox" name="cr09" id="cr09" value="北京4" />
                <label for="cr09">北京4</label>
                <input type="checkbox" name="cr09" id="cr09" value="北京4" />
                <label for="cr09">北京4</label>
            </div>
        </div>
    </div>
<!--
    <input type="text" name="address2" id="address2" size="20">
    <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>
 -->
</body>
</html>

jquery.plugin.css

body{font-size:12px;}

#selectItem{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;}
.selectItemhidden{display:none;}
.selectItemcont{padding:8px;}
/*.selectItemcls{clear:both;font-size:0px;height:0px;overflow:hidden;}*/
/*#selectItem2{background:#FFF;position:absolute;top:0px;left:center;border:1px solid #000;overflow:hidden;width:240px;z-index:1000;}*/

jquery.plugin.js

(function($){
$.fn.bgIframe = $.fn.bgiframe = function(s) {
    // This is only for IE6
    if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
        s = $.extend({
            top     : ‘auto‘, // auto == .currentStyle.borderTopWidth
            left    : ‘auto‘, // auto == .currentStyle.borderLeftWidth
            width   : ‘auto‘, // auto == offsetWidth
            height  : ‘auto‘, // auto == offsetHeight
            opacity : true,
            src     : ‘javascript:false;‘
        }, s || {});
        var prop = function(n){return n&&n.constructor==Number?n+‘px‘:n;},
            html = ‘<iframe class="bgiframe"frameborder="0"tabindex="-1"src="‘+s.src+‘"‘+
                       ‘style="display:block;position:absolute;z-index:-1;‘+
                           (s.opacity !== false?‘filter:Alpha(Opacity=\‘0\‘);‘:‘‘)+
                           ‘top:‘+(s.top==‘auto‘?‘expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\‘px\‘)‘:prop(s.top))+‘;‘+
                           ‘left:‘+(s.left==‘auto‘?‘expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\‘px\‘)‘:prop(s.left))+‘;‘+
                           ‘width:‘+(s.width==‘auto‘?‘expression(this.parentNode.offsetWidth+\‘px\‘)‘:prop(s.width))+‘;‘+
                           ‘height:‘+(s.height==‘auto‘?‘expression(this.parentNode.offsetHeight+\‘px\‘)‘:prop(s.height))+‘;‘+
                    ‘"/>‘;
        return this.each(function() {
            if ( $(‘> iframe.bgiframe‘, this).length == 0 )
                this.insertBefore( document.createElement(html), this.firstChild );
        });
    }
    return this;
};

})(jQuery);

构建的js

var selectItemhidden = jQuery("<div></div>").addClass("selectItemhidden").attr("id","selectItem");

var selectItemtit = jQuery("<div></div>").addClass("selectItemtit bgc_ccc").attr("id","selectItemAd");
var selectItemleft = jQuery("<h2></h2>").addClass("selectItemleft").attr("id","selectItemTitle");
var selectItemright = jQuery("<div></div>").addClass("selectItemright").attr("id","selectItemClose");

var selectItemcont = jQuery("<div></div>").addClass("selectItemcont").attr("id","selectItemCount");
var selectSub = jQuery("<div></div>").attr("id","selectSub");
var checkbox = jQuery("<input>").attr("type","checkbox").attr("name","cr01").attr("id","cr01").val("北京1");
var label = jQuery("<label>").attr("for","cr01").html("北京");

var title = selectItemtit.append(selectItemleft).append(selectItemright);
var content = selectItemcont.append(selectSub.append(checkbox).append(label));

selectItemhidden.append(title).append(content);

时间: 2024-10-24 13:26:41

jquery input选择弹框的相关文章

jQuery一次弹框实例

服务器环境下: <!doctype html><html><head><meta charset="utf-8"><title>弹框</title><script type="text/javascript" src="js/jquery-3.3.1.min.js"></script><script type="text/javascr

jquery点击弹框外层关闭弹框

$(document).bind("click",function(e){            if($( e.target ).closest(".game-container").length == 0){                alert(111);                $(".game-container").hide();//game-container是弹框的样式名称            }else{      

有定位的含有 input的弹框,在有些手机光标乱跳

弹框定位不能使用 fixed ,需要改成absolute .cus_dialog { height: 13.133333rem; width: 7.399999rem; position: absolute; top:6%; left: 50%; transform: translateX(-50%); z-index: 1000; }

禁止长按微信页面出现默认选择弹框

长按微信中打开的h5页面默认会有弹框,如图: 如果我们不想出现这个,可以加: document.oncontextmenu=function(e){ e.preventDefault(); } oncontextmenu 事件在元素中用户右击鼠标时触发并打开上下文菜单. 原文地址:https://www.cnblogs.com/leaf930814/p/8497248.html

jquery 点击弹框

<a href="#" class="big-link" data-reveal-id="myModal" data-animation="fade">jquery点我弹出</a> <div id="myModal" class="reveal-modal"> <h1> jquery弹出层 </h1> <p> jQu

小插件: 例 新增操作人 点击文本框需要展示所有的人员提供选择弹框 人员信息全部自动带出来

效果图: 描述: 点击人员input 弹出模态框提供选择 , 选择确定后人员信息自动带入以下文本框 页面: <div class="form-group"> <label class="col-md-3 control-label">维修人系统编号:</label> <div class="col-md-8"> <input id="RepairUserAccount" n

jQuery input 下拉框焦点事件

本章主要讲解如何实现select下拉列表可输入效果 ps:input提供输入,然后用ul去模拟一个select下拉列表效果即可,关键在于点击div之外的地方隐藏ul,下面是html基本结构: <div class="input-box"> <input type="text" class="input" value="Holle Word" /> <span class="tip-l&q

Jquery学习笔记(8)--京东导航菜单(2)增加弹框

京东导航,添加中间的弹框栏,使用position定位,放在左侧栏的li标签里面,成为一个整体,保证鼠标在弹框里的时候,弹框不消失: 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <script src="jquery.js&quo

jQuery实现复选框全选/全部取消/反选/获得选择的值

本地单文件上传脚本,命名uf 这是在本机上做的测试,利用bpcs_uploader脚本实现,只是进行简单的封装,自动完善云端文件路径. 技术要点:使用dirname获取文件所在目录,使用pwd获取文件完整路径,并作为云端文件路径. #!/bin/bash cur_dir=$(cd "$(dirname "$1")"; pwd) name=$(basename "$1") /home/grm/bin/bpcs_uploader/bpcs_uploa