gpt4 book ai didi

Javascript datePicker Controller : Hard Coded string working, 变量不是

转载 作者:行者123 更新时间:2023-11-30 08:12:30 25 4
gpt4 key购买 nike

我正在使用可以在此处找到的日期选择器:

http://www.frequency-decoder.com/2011/10/11/unobtrusive-accessible-datepicker-widgit-v6

只要我对对象的 ID 进行硬编码,我就可以正常工作。即

var newid = "date" + maxidOnce.toString();
datePickerController.createDatePicker({
formElements:{"date1":"%Y-%m-%d"},
statusFormat:"%l, %d %F %Y",
noFadeEffect:true
});

但是,如果我用变量替换 id,它就不再有效了。我看不出有什么区别。

var newid = "oncedate" + maxidOnce.toString();
datePickerController.createDatePicker({
formElements:{newid:"%Y-%m-%d"},
statusFormat:"%l, %d %F %Y",
noFadeEffect:true
});

最佳答案

I don't see how there is any difference.

区别在于 JavaScript 对象键在使用 object literals 时不被解释为变量 .使用 bracket notation相反。

var newid = "oncedate" + maxidOnce;
var formElts = {};
formElts[newid] = "%Y-%m-%d";
datePickerController.createDatePicker({
formElements: formElts,
statusFormat: "%l, %d %F %Y",
noFadeEffect: true
});

// or, to write it another way,
var newid = "oncedate" + maxidOnce;
var options = {
formElements: {},
statusFormat: "%l, %d %F %Y",
noFadeEffect: true
};
options.formElements[newid] = "%Y-%m-%d";
datePickerController.createDatePicker(options);

关于Javascript datePicker Controller : Hard Coded string working, 变量不是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8321317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com