Javascript 变量作为链中的函数名称
我正在尝试将从表单元素捕获的变量拉入函数链。变量值需要充当函数名称。示例:
<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="DayOfWeek" value="thursday" />Thursday
<input type="radio" id="DayOfWeek" name="DayOfWeek" value="friday" />Friday
</form>
脚本:
var **monthday**=$("input[name='DayOfWeek']:checked").val();
NewDate = Date.parse(NewDate).add(1).month().**monthday**();
我的问题是让变量“monthday”值充当该链中的函数名称。我是否有一个“呃”时刻或者这是不可能的?
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="DayOfWeek" 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:
Date.parse(NewDate).add(1).month()[monthday]();
?How about this:
Date.parse(NewDate).add(1).month()[monthday]();
?使用括号表示法:
Use bracket notation: