开发者

Javascript variable as function name in chain

I am trying to pull a variable that is captured from a form element in to a function chain. The variable value needs to act as a function name. Example:

<form name="myform">
  <input type="radio" id="DayOfWeek" name="DayOfWeek" value="monday" />Monday
  <input type="radio" id="DayOfWeek" name="DayOfWeek" value="tuesday" />Tuesday
  <input type="radio" id="DayOfWeek" name="DayOfWeek" value="wednesday" />Wednesday
  <input type="radio" id="DayOfWeek" name="DayOf开发者_StackOverflow社区Week" value="thursday" />Thursday
  <input type="radio" id="DayOfWeek" name="DayOfWeek" value="friday" />Friday
</form>

script:

var **monthday**=$("input[name='DayOfWeek']:checked").val();
NewDate = Date.parse(NewDate).add(1).month().**monthday**();

My problem has been getting the variable 'monthday' value to act as the function name in that chain. Am I having a 'duh' moment or is this not possible?


How about this:Date.parse(NewDate).add(1).month()[monthday]();?


Use bracket notation:

var monthday = $("input[name='DayOfWeek']:checked").val();
NewDate = Date.parse(NewDate).add(1).month()[monthday]();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜