用trigger触发datepicker

jQuery UI的datepicker没有icon图片,工作需要,自己写了一个,原理是用div包裹住datepicker的input和一个button,隐藏掉input,而button被点击后也可以触发input从而显示datepicker。

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <script src="js/jquery-1.11.3.min.js"></script>
        <script src="js/jquery-ui.min.js"></script>
        <link rel="stylesheet" href="css/jquery-ui.css" />
        <style>
            .dateCon{width:150px; height:30px; display:table-cell; vertical-align:middle; border:1px solid #eee; padding-left:5px;}
            .dateCon input[type="text"]{width:128px; height:15px; line-height:15px; font-size:15px; border:0; float:left; display:inline-block;}
            .dateCon input[type="text"]:focus{outline:none;}
            .dateCon input[type="button"]{width:20px; height:20px; float:right; display:inline-block;}
        </style>
    </head>
    <body>
        <div class="dateCon">
            <input type="text" id="datepicker1" />
            <input type="button" id="dateIcon" />
        </div>
        
        <script>
            $(document).ready(function(){
                $("#datepicker1").datepicker();
                
                $("#dateIcon").click(function(){
                    $("#datepicker1").trigger("focus");
                });
            });
        </script>
    </body>
</html>

 

转载于:https://www.cnblogs.com/zcynine/p/5048700.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值