2012-10-02 70 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>