English 中文(简体)
如果是星期六、星期一或星期三,则人口统计表的分类
原标题:jquery script to populate select list / drop down if it is Saturday, Monday or Wednesday

我要求以DD-MM-YYYYY格式填写甄选名单,并附上以下文字。 它以90天的日期选定名单。

现在客户的要求发生了变化,他只想填满星期六、星期一或星期三的日期。 我无法解决这个问题,我试图修改文字,但并没有工作。

以下文字正在发挥作用。 赞赏在这方面提供的任何帮助。

<script>
$(function(){
    function pad(n){return n<10 ?  0 +n : n}
    var date = new Date();
    var selectElement = $( <select name="dddDate" class="ddDate" > ), optionElement;
    for (var count =0; count < 90; count++){
        formattedDate = pad(date.getUTCDate()) +  -  + pad(date.getUTCMonth()+1) +  -  +  date.getUTCFullYear();
        optionElement = $( <option> )
        optionElement.attr( value ,formattedDate);
        optionElement.text(formattedDate);
        selectElement.append(optionElement);
        date.setDate(date.getDate() +1);
    }
    $( #ddDate ).append(selectElement);
});
</script>

<body>
<div id="ddDate"> </div>
</body>
最佳回答

Date.getDay( ): return the day-of-the-week field of a Date. Return values are between 0 (Sunday) and 6 (Saturday). http://jsfiddle.net/UvDEa/

    $(function(){
    function pad(n){return n<10 ?  0 +n : n}
    var date = new Date();
    var selectElement = $( <select name="dddDate" class="ddDate" > ), optionElement;
    for (var count =0; count < 90; count++){
        var day = date.getUTCDay();
        if (day == 6 || day == 1 || day == 3) {
          formattedDate = pad(date.getUTCDate()) +  -  + pad(date.getUTCMonth()+1) +  -  +  date.getUTCFullYear();
          optionElement = $( <option> )
          optionElement.attr( value ,formattedDate);
          optionElement.text(formattedDate);
          selectElement.append(optionElement);  
        }
        date.setDate(date.getDate() +1);
    }
    $( #ddDate ).append(selectElement);
    });
问题回答

可为此使用<代码>。

if ($.inArray(date.getUTCDay(), [6, 1, 3]) > -1) {
    // Include this date
}

纽约总部 大会和会议管理部印发

仅加一,如果对“天空”功能进行这种检查。

if( formattedDate.getDay() == 1 || formattedDate.getDay() == 3 || formattedDate.getDay() == 6)
{
    optionElement = $( <option> );
    optionElement.attr( value ,formattedDate);
    optionElement.text(formattedDate);
    selectElement.append(optionElement);
}

EDIT:

$(function(){
function pad(n){return n<10 ?  0 +n : n}
var date = new Date();
var selectElement = $( <select name="dddDate" class="ddDate" > ), optionElement;
for (var count =0; count < 90; count++){
    formattedDate = pad(date.getUTCDate()) +  -  + pad(date.getUTCMonth()+1) +  -  +  date.getUTCFullYear();
if( formattedDate.getDay() == 1 || formattedDate.getDay() == 3 || formattedDate.getDay() == 6)
{
    optionElement = $( <option> );
    optionElement.attr( value ,formattedDate);
    optionElement.text(formattedDate);
    selectElement.append(optionElement);
 }
    date.setDate(date.getDate() +1);
}
$( #ddDate ).append(selectElement);

iii

这应当行之有效。

$(function(){
function pad(n){return n<10 ?  0 +n : n}
var date = new Date();
var selectElement = $( <select name="dddDate" class="ddDate" > ), optionElement;
for (var count =0; count < 90; count++){
    formattedDate = pad(date.getUTCDate()) +  -  + pad(date.getUTCMonth()+1) +  -  +  date.getUTCFullYear();
if( date.getUTCDay() == 1 || date.getUTCDay() == 3 || date.getUTCDay() == 6)
{
    optionElement = $( <option> );
    optionElement.attr( value ,formattedDate);
    optionElement.text(formattedDate);
    selectElement.append(optionElement);
 }
    date.setDate(date.getDate() +1);
}
$( #ddDate ).append(selectElement);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签