javascript
  • html
  • twitter-bootstrap
  • 2015-10-05 202 views 1 likes 
    1

    我的引導datetimepicker具有以下html。我想禁用<input>並強制用戶使用datetimepicker。我試過使用disabledreadonly="readonly"屬性。但添加屬性後,我的datetimepicker不起作用。有什麼建議麼?使用datetimepicker禁用輸入字段

    <div class='input-group date' id='startDate'> 
         <input type='text' class="form-control" /> 
         <span class="input-group-addon"> 
          <span class="glyphicon glyphicon-calendar"></span> 
         </span> 
    </div> 
    
    $('#startDate').datetimepicker({ 
        format: "YYYY-MM-DD", 
        useCurrent: true, 
        viewMode: "days" 
    }); 
    
    +0

    http://stackoverflow.com/questions/18569292/bootstrap-datepicker-disable-feature –

    +0

    你使用什麼插件?在這裏工作正常:http://jsfiddle.net/IvinvinDominin/hz6xuu0o/ –

    +0

    我使用http://eonasdan.github.io/bootstrap-datetimepicker/ – root

    回答

    1

    您可以將disabled屬性添加到您的輸入,如:

    <input type='text' class="form-control" name="startDate" disabled />  
    

    演示:http://jsfiddle.net/IrvinDominin/hz6xuu0o/

    +0

    我試過了。它不適用於我的。我會用我的JS編輯這個問題。如果有幫助。 – root

    +0

    按預期工作在這裏:http://jsfiddle.net/IrvinDominin/hz6xuu0o/1/?你能提供這個問題的演示嗎? –

    +0

    這很奇怪。當我把它放到小提琴裏面的時候它就起作用了。但它在我的.jsp上不起作用 – root

    0

    所有東西都在輸入格子裏打起來,所以它把datetimepicker當作輸入。因此,需要輸入的div出或採取的DateTimePicker出

    1

    我設法得到可接受的解決方案如下:

    $(".date").datetimepicker({ 
        defaultDate: moment(), 
        format: 'YYYY-MM-DD' 
    }).on('keypress paste', function (e) { 
        e.preventDefault(); 
        return false; 
    }); 
    

    希望它也適用於您!

    相關問題