admin管理员组文章数量:1379395
I'd like to use a "data-dateformat" attribute to set the dateformat option of a jQueryUI Datepicker
so I can do this on my page
<input name="t1" type="text" class="datepicker" data-dateformat="MM YY">
<input name="t2" type="text" class="datepicker" data-dateformat="DD MM y">
and the datepicker will use the correct format
I tried
$( ".datepicker" ).datepicker({
dateFormat: $(self).attr('data-dateformat')
});
but that doesn't work.
Is there some way to do that ?
I'd like to use a "data-dateformat" attribute to set the dateformat option of a jQueryUI Datepicker
so I can do this on my page
<input name="t1" type="text" class="datepicker" data-dateformat="MM YY">
<input name="t2" type="text" class="datepicker" data-dateformat="DD MM y">
and the datepicker will use the correct format
I tried
$( ".datepicker" ).datepicker({
dateFormat: $(self).attr('data-dateformat')
});
but that doesn't work.
Is there some way to do that ?
Share Improve this question asked Nov 2, 2012 at 4:11 Jo ErlangJo Erlang 3277 silver badges15 bronze badges 1- 1 What is self? Where do you assign it? Are you expecting it to be the input element? – loganfsmyth Commented Nov 2, 2012 at 4:13
2 Answers
Reset to default 8Your self
value will not have the proper scope for individual elements. You need to loop over each datepicker.
Try this:
$(".datepicker").each(function(){
var $this = $(this);
$this.datepicker({
dateFormat: $this.attr('data-dateformat')
});
});
You can also use the jQuery data
method.
$(".datepicker").each(function(){
var $this = $(this);
$this.datepicker({
dateFormat: $this.data('dateformat')
});
});
you can try this may work
$( ".datepicker" ).datepicker({
dateFormat: $(this).data('dateformat')
});
本文标签: javascriptUsing a dataattribute to set an option on jQueryUI calenderStack Overflow
版权声明:本文标题:javascript - Using a data-attribute to set an option on jQueryUI calender - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744485643a2608432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论