简体   繁体   English

jQuery-ui多个datepicker具有不同的字体大小

[英]Jquery-ui multiple datepicker with different font size

I want to be able to control the font size of multiple jquery-ui datepicker independantly. 我希望能够独立地控制多个jquery-ui datepicker的字体大小。 I have 2 datepicker linked to a text input. 我有2个datepicker链接到文本输入。 Declared like this: 这样声明:
$('#Date1').datepicker({firstDay: 1,showWeek: true});
$('#Date2').datepicker({firstDay: 1,showWeek: true});

In the HTML, they are used like this: 在HTML中,它们的用法如下:
<input type="text" size=10 maxlength=10 id="Date1">
<input type="text" size=10 maxlength=10 id="Date2">

How do I change the font size of the datepicker independently? 如何独立更改日期选择器的字体大小?
<style type="text/css"> .ui-datepicker { font-size: 12px; } </style>
affects both datepicker. 同时影响两个日期选择器。
<style type="text/css"> #Date1 { font-size: 12px; } </style> <style type="text/css"> #Date1 { font-size: 12px; } </style> does nothing. <style type="text/css"> #Date1 { font-size: 12px; } </style>不执行任何操作。
If I create a <div> arount the <input> it also affects the text input, which I do not want. 如果我创建一个<div>周围的<input>它也会影响我不需要的文本输入。

Thanks. 谢谢。

尝试

$('#Date1 > .ui-datepicker').css({ 'font-size': 12px});

you can't change the font size independently, it uses the SAME element for both datepickers, here's my JSfiddle, if you inspect element on the input fields you will see what I mean. 您不能单独更改字体大小,它对两个日期选择器都使用SAME元素,这是我的JSfiddle,如果您检查输入字段中的元素,您将明白我的意思。

http://jsfiddle.net/m7q3H/56/ http://jsfiddle.net/m7q3H/56/

If you a div you can target just the datepicker not the input, like so 如果您是div,则只能定位日期选择器而不是输入,就像这样

  div#newDiv .ui-datepicker:first-child  //gets you the first one
  div#newDiv .ui-datepicker:last-child  //gets you the last one

Since the datepicker uses the same one datepicker regardless of how many instances you create, the best thing to do would be to add and remove classes dependant on the instance. 由于datepicker使用相同的一个datepicker,而不管您创建了多少个实例,因此最好的办法是添加和删除依赖于该实例的类。

See this jsFiddle example . 请参阅此jsFiddle示例

jQuery jQuery的

$('#Date1').datepicker({
    firstDay: 1,
    showWeek: true
});
$('#Date2').datepicker({
    firstDay: 1,
    showWeek: true,
    beforeShow: function(input, inst) {
       $('.ui-datepicker').addClass('bigFont');
    },
    onClose:function(input, inst) {
       $('.ui-datepicker').removeClass('bigFont');
    }
});​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM