简体   繁体   English

如何更改CSS在输入控件上定义的日期选择器

[英]How to change date-picker defined by CSS on input control

I have a date-picker control that is being added using CSS on an input control that is added dynamically at run time. 我有一个日期选择控件,正在使用CSS在运行时动态添加的输入控件上添加日期选择控件。 The HTML looks like so: HTML看起来像这样:

<input name="date1" class="date-picker input-medium" type="text" value="2018-10-18" data-date-format="yyyy-mm-dd">

I want to change the formatting on this date-picker control but I'm having trouble figuring out how to do so. 我想更改此日期选择器控件上的格式,但是我很难弄清楚该如何做。 This Javascript below runs after the HTML is generated: 下面的Javascript在生成HTML之后运行:

    $('.date-picker').datepicker({
    showButtonPanel: true,
    changeMonth: true,
    changeYear: true,
    calendarWeeks:true,
    clearBtn: true,
    });

I was hoping code like above would change it, I threw in a few non-default options just to verify that it changes but it just looks like the default version. 我希望上面的代码可以更改它,我添加了一些非默认选项只是为了验证它是否已更改,但它看起来像默认版本。

Any idea how I go about changing the formatting on the date picker on my input control? 知道如何更改输入控件上日期选择器的格式吗? I'm OK if it changes all date pickers on the page or if its just specific to this one date picker and I can apply it to all date pickers (in the event there are multiples, which could happen). 我可以确定它是否更改了页面上的所有日期选择器,或者它仅特定于此一个日期选择器,并且可以将其应用于所有日期选择器(如果有多个,则可能会发生)。

Maybe I'm confusing this with my javascript, as there seem to be jquery date pickers and boot strap date pickers and its not clear to me if they're actually both the same date pickers or not, so maybe I need to do something different. 也许我将其与我的javascript混淆了,因为似乎有jquery日期选择器和Bootstrap日期选择器,并且我不清楚它们是否实际上都是相同的日期选择器,所以也许我需要做一些不同的事情。

It's not the ideal solution, but I changed the JavaScript in bootstrap-datapicker.js so it sets language from a variable I set with the current site culture in the constructor. 这不是理想的解决方案,但是我在bootstrap-datapicker.js中更改了JavaScript,因此它根据我在构造函数中使用当前站点区域设置设置的变量设置语言。 I could do the same for formatting (I actually really just wanted to change the language but for the first post figured it was easier to just ask about changing formatting). 我可以对格式化进行相同的操作(实际上我实际上只是想更改语言,但第一篇文章认为,仅询问更改格式会更容易)。

options.language = cultureName;

Also to note, while someone (not me!) had put in the code I pasted above to change date-picker values, that's how to change values with the jquery UI datepicker but the CSS class is actually applying the bootstrap datepicker. 还要注意,虽然有人(不是我!)在我上面粘贴的代码中更改了日期选择器的值,但这是使用jquery UI datepicker更改值的方法,但是CSS类实际上是在应用bootstrap datepicker。

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

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