---原始代码----
$(function () {
var options = {
xaxis: { mode: "time", tickLength: 5 },
selection: { mode: "x" },
crosshair: { mode: "x" }
};
});
当 rlt = true 时,我希望十字准线:{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" }
};
}
});
答案 0 :(得分:6)
对我有用,但你可以这样写:
var rlt = true;
var options = {
xaxis: { mode: "time", tickLength: 5 },
selection: { mode: "x" }
};
if (rlt) options.crosshair = { mode: "x" }
答案 1 :(得分:1)
如果您在options.crosshair.mode
内查看$(function () {}
,那么您的工作有效
变量的作用域。