1

你能告诉我如何在文本字段上设置默认日期吗?实际上我有一个按钮点击弹出屏幕显示在日期字段中,我在日期上显示当前日期。

  <div data-role="popup" id="CaseInformationScreen" data-close-btn="none"  data-overlay-theme="a" data-dismissible="false">
                <div data-role="header" data-theme="b" >

                    <a href="#" data-role="button" data-corners="false" id="Cancel">Cancel</a>
                    <h1>Case Information</h1>
                    <a href="#" data-role="button" data-corners="false" id="AddButton">Add</a>
                </div>

                <div data-role="content">
                    <div><img src="img/Documents.png"/></div>
                    <div data-role="fieldcontain">
                        <label for="text-12" style="text-align:top;margin-left: 0px;">Case Name:</label>
                        <input name="text-12" id="text-12" value="" type="text" class="caseName_h" autocorrect="off">
                    </div>
                    <div data-role="fieldcontain">
                        <label for="caseDate" style="text-align:left;margin-left: 0px;" >Case Date:</label>
                        <input name="caseDate" id="caseDate" value="" type="date" class="caseDate_h" >
                           <!--input name="mydate2" id="mydate2" type="date" data-role="datebox" class="caseDate_h" data-options='{"mode": "calbox","useNewStyle":true,"zindex":1200}'/-->
                    </div>
                    <div data-role="fieldcontain">
                        <label for="textarea-12">Case Notes :</label>
                        <textarea cols="40" rows="8" name="textarea-12" id="text-12" class="caseTextArea_h" autocorrect="off"></textarea>
                    </div>
                </div>
            </div>
4

2 回答 2

1

工作示例:http: //jsfiddle.net/Gajotres/Ndc2b/

HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>jQM Complex Demo</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
        <!--<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>-->
        <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>    
    </head>
    <body>
        <div data-role="page" id="index">
            <div data-theme="b" data-role="header">
                <h1>Index page</h1>
            </div>

            <div data-role="content">
                <a href="#CaseInformationScreen" data-rel="popup" data-role="button" data-inline="true" data-transition="pop">Basic Popup</a>
                <div data-role="popup" id="CaseInformationScreen" data-close-btn="none"  data-overlay-theme="a" data-dismissible="false">
                    <div data-role="header" data-theme="b" >

                        <a href="#" data-role="button" data-corners="false" id="Cancel">Cancel</a>
                        <h1>Case Information</h1>
                        <a href="#" data-role="button" data-corners="false" id="AddButton">Add</a>
                    </div>

                    <div data-role="content">
                        <div><img src="img/Documents.png"/></div>
                        <div data-role="fieldcontain">
                            <label for="text-12" style="text-align:top;margin-left: 0px;">Case Name:</label>
                            <input name="text-12" id="text-12" value="" type="text" class="caseName_h" autocorrect="off"/>
                        </div>
                        <div data-role="fieldcontain">
                            <label for="caseDate" style="text-align:left;margin-left: 0px;" >Case Date:</label>
                            <input name="caseDate" id="caseDate" value="" type="date" class="caseDate_h" />

                        </div>
                        <div data-role="fieldcontain">
                            <label for="textarea-12">Case Notes :</label>
                            <textarea cols="40" rows="8" name="textarea-12" id="text-12" class="caseTextArea_h" autocorrect="off"></textarea>
                        </div>
                    </div>
                </div>                    
            </div>
        </div>    
    </body>
</html>   

Javascript:

$(document).on('pagebeforeshow', '#index', function(){ 
    $(document).on( "popupafteropen", "#CaseInformationScreen",function( event, ui ) {
        var today = new Date();   
        var dd = today.getDate();
        var mm = today.getMonth()+1; //January is 0!

        var yyyy = today.getFullYear();    

        $('#caseDate').val(dd + '-' + mm + '-' + yyyy);    
    });        
});
于 2013-07-19T08:33:10.170 回答
-1

有一个非常简单的解决方案。
这就是我所做的:

$(document).ready(function(){
    $("#date1").datepicker();
    $("#date1").datepicker('setDate', 'today');
});

<input type="text" id="date1">
于 2018-01-31T20:10:59.163 回答