更改 if else 语句中的 Jquery 变量
---原始代码----
$(function () {
var options = {
xaxis: { mode: "time", tickLength: 5 },
selection: { mode: "x" },
crosshair: { mode: "x" }
};
});
当rlt=true时,我希望crosshair: { mode: "x" }位于选项变量内部>。
以下是我的代码,但它不正确。有人可以指出错误吗?
谢谢!
$(function () {
var rlt = true;
var options;
if(rlt){
options = {
xaxis: { mode: "time", tickLength: 5 },
selection: { mode: "x" },
crosshair: { mode: "x" }
};
}else{
options = {
xaxis: { mode: "time", tickLength: 5 },
selection: { mode: "x" }
};
}
});
---Original code----
$(function () {
var options = {
xaxis: { mode: "time", tickLength: 5 },
selection: { mode: "x" },
crosshair: { mode: "x" }
};
});
I want crosshair: { mode: "x" } to be inside of options variable when rlt=true.
Following is my code, but it's not correct.Is there anyone can point error out?
Thanks!
$(function () {
var rlt = true;
var options;
if(rlt){
options = {
xaxis: { mode: "time", tickLength: 5 },
selection: { mode: "x" },
crosshair: { mode: "x" }
};
}else{
options = {
xaxis: { mode: "time", tickLength: 5 },
selection: { mode: "x" }
};
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我有用,但你可以这样写:
works for me, but you can write it this way:
如果您在
$(function () {}
内检查options.crosshair.mode
,您所拥有的将有效变量的作用域在哪里。
What you have works if you are checking
options.crosshair.mode
inside the$(function () {}
where the variable is scoped.