使用jquery datepicker选择选择日期的星期数 [英] Select the week number of the date picked using jquery datepicker

查看:132
本文介绍了使用jquery datepicker选择选择日期的星期数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码来选择一个日期,然后将其转换为星期数.

I have the following code for selecting a date which I then want to convert to a week number.

    $(".calendar").datepicker({
        showWeek: true,
        onSelect: function(dateText, inst) {
            dateFormat: "'Week Number '" + $.datepicker.iso8601Week(new Date(dateText)),
            alert($.datepicker.iso8601Week(new Date(dateText)))
        }
    });

警报显示正确的星期数,但日期根本没有重新格式化.

The alert shows the correct week number, but the date does not reformat at all.

我无法将dateFormat函数移到onSelect之外,因为这不会导致任何事情发生.

I can't move the dateFormat function outside of the onSelect because this causes nothing to happen.

我想实现的是在文本字段中输入类似第13周"的字样

What I would like to achieve is the text field to say something like "Week Number 13"

有什么想法吗?

http://jsfiddle.net/ENG66/

推荐答案

我已经更新了小提琴以使其正常工作: http://jsfiddle.net/ENG66/11/

I've updated the fiddle to make it work: http://jsfiddle.net/ENG66/11/

在onselect事件中,您需要使用.val()覆盖文本框值的设置

In the onselect event, you need to use .val() to override the setting of the textbox value

$(".calendar").datepicker({
        showWeek: true,
        onSelect: function(dateText, inst) {
            $(this).val("'Week Number '" + $.datepicker.iso8601Week(new Date(dateText)));
        }
    });​

编辑

正如Igor Shastin在下面的评论中指出的那样,我们已经在 inst.input

As Igor Shastin pointed out in his comment below we already have the text box in inst.input

inst.input.val($.datepicker.iso8601Week(new Date(dateText)));

这篇关于使用jquery datepicker选择选择日期的星期数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆