最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavascriptJQuery GetDay() - Stack Overflow

programmeradmin1浏览0评论

I have the following code:

/

I'm pletely new to javascript, this is my first time using it. The values of the HTML selects MUST be 01,02 etc, that's why I had to use a big long if else statement. The values have to be submitted to an application on a server, which is extremely fussy about what way it takes in values.

Why won't it set the day as 15 (today) in the select box?

I have the following code:

http://jsfiddle/SPWWx/

I'm pletely new to javascript, this is my first time using it. The values of the HTML selects MUST be 01,02 etc, that's why I had to use a big long if else statement. The values have to be submitted to an application on a server, which is extremely fussy about what way it takes in values.

Why won't it set the day as 15 (today) in the select box?

Share Improve this question edited Jul 15, 2010 at 11:10 Marcus asked Jul 15, 2010 at 11:04 MarcusMarcus 31 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

You have a few issues, you're not including jQuery on the left, the element has a name not an ID or CID, so it needs to be id="CID" or your selector needs to be select[name='CID']. Last, you need to pass a string to .val() to get the result you want, otherwise it's trying to set it to "4", which doesn't equal "04".

You can shorten all your code down to this though:

var day = new Date().getDate().toString();
$("#CID").val(day.length == 1 ? "0" + day : day);​

You can test it here, also as Jamiec points out, you want .getDate() to get the date of the month as opposed to .getDay() which is of the week.

because the element's name is CID, not it's id! $('#CID') selects the element with the id CID.

发布评论

评论列表(0)

  1. 暂无评论