2012-10-02 68 views
3

我有一個帶佔位符數據的Kendo UI日期選擇器。下面是HTML:Kendo UI - 佔位符 - 樣式

<input type="text" class="datepicker"' placeholder="yyyy-mm-dd" /> 

這裏是JavaScript:

var start = $(".datepicker").kendoDatePicker({ 
     format: "yyyy-MM-dd", 
     parseFormats: ["MM/dd/yyyy"], 
     change: startChange 
    }).data("kendoDatePicker"); 

劍道UI爲用戶輸入的數據顯示日期選擇器在同一樣式的佔位符數據。我想以不同方式設置佔位符數據的樣式。具體來說,我希望文本是灰色和斜體。當用戶輸入數據時,樣式會變爲純黑色(非斜體)。有關如何做到這一點的任何想法?

回答

5

那麼,placeholder是一個HTML5屬性,並不指定Kendo控件。據我瞭解,Kendo不會爲瀏覽器支持的佔位符提供任何支持,請記住只有一些瀏覽器支持此屬性; IE沒有。 無論如何,要設置佔位符的樣式,您必須使用供應商前綴CSS屬性see here

3

我用this..it將在你的HTML工作,你可以風格太:)

<script> 
    // This adds 'placeholder' to the items listed in the jQuery .support object. 
    jQuery(function() { 
     jQuery.support.placeholder = false; 
     test = document.createElement('input'); 
     if('placeholder' in test) jQuery.support.placeholder = true; 
    }); 
    // This adds placeholder support to browsers that wouldn't otherwise support it. 
    $(function() { 
     if(!$.support.placeholder) { 
      var active = document.activeElement; 
      $(':text').focus(function() { 
       if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) { 
        $(this).val('').removeClass('hasPlaceholder'); 
       } 
      }).blur(function() { 
       if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) { 
        $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder'); 
       } 
      }); 
      $(':text').blur(); 
      $(active).focus(); 
      $('form:eq(0)').submit(function() { 
       $(':text.hasPlaceholder').val(''); 
      }); 
     } 
    }); 
    </script>