按钮点击时显示datepicker插件?

时间:2015-08-04 05:42:29

标签: javascript jquery html css datepicker

我使用jQuery UI中的日期选择器并根据我的需要自定义其CSS。我想点击按钮点击datepicker,它本身显示dateinfo like this.

我当前的HTML代码:

<div class="date-pickup-block">
                        <div type="text">
                        <input type="text" id="datepicker"/>
                        </div>                        
                    </div>

我的javascript代码是:

$(function(){
    $('#datepicker').datepicker({
        showOn: 'button',
        buttonText: 'Show Date',

        dateFormat: "D dd/mm/yy",           
        inline: true,
        showOtherMonths: false,
        dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
    });

    $(".ui-datepicker-trigger").mouseover(function(){
        $(this).css('cursor','pointer');
    });
});

和我当前的日期选择器,当我点击show Date时,它看起来像this.

CSS COde:

.ui-datepicker {
    background-color: #fff;
    width: 255px;
    height: auto;
    margin: 5px auto 0;
    padding: 15px;

    }

    .ui-datepicker a{
        text-decoration: none;
        }

    .ui-datepicker table{
        width: 100%;        
        }

    .ui-datepicker thead{
        color: #f36846;
        }

    .ui-datepicker-header{
        color: #f36846;
        font-family: 'proxima_nova_ltsemibold';
        font-size: 15px;
        letter-spacing: 1px;
        text-transform: uppercase;
        }

    .ui-datepicker tbody:before {
        content: "-";
        display: block;
        line-height: 1em;
        color: transparent;
        }

    .ui-datepicker-title{
        text-align: center;
        }

    .ui-datepicker-prev, .ui-datepicker-next {
        display: inline-block;
        width: 30px;
        height: 30px;
        text-align: center;
        cursor: pointer;        
        background-repeat: no-repeat;
        line-height: 600%;
        overflow: hidden;
        }

    .ui-datepicker-prev {
        background-image: url('../imgs/pickup-details/calander_left.png');      
        float: left;
        background-position: center 2px;
        }

    .ui-datepicker-next {
        background-image: url('../imgs/pickup-details/calander_right.png');
        float: right;
        background-position: center 2px;
        }

    .ui-datepicker tbody td {

        font: 10px 'proxima_nova_ltsemibold';

        background-color: #fff;
        border: 1px solid #dbdbdb;
        }

    .ui-datepicker td span, .ui-datepicker td a {
        color: #000;
        display: inline-block;
        height: 31px;
        line-height: 31px;
        text-align: center;
        width: 31px;
        }


    .ui-datepicker-calendar .ui-state-active {
        background: #f36846;
        color: #fff;   
        }

我不知道mucj jQuery,因此jQuery很难定制。我需要在HTML和jQuery中进行哪些更改才能使其看起来like this.

1 个答案:

答案 0 :(得分:0)

<script type="text/javascript">
$(function () {
    $("#datepicker").datepicker({
        constrainInput: true,
        showOn: 'button',
        buttonText: 'Select'
    }); });</script><input id="datepicker" disabled="disabled" />

使用此功能