我在访问全局变量时遇到问题,想访问
selection1 = $("#slider").slider( "value" );
selection2 = $("#slider2").slider( "value" );
在 jQuery 函数内部只需通过选择调用 calcTmpl(selection1, selection2) ,但这似乎无法通过在函数外部声明变量来实现,如下所示:var selection1 = $("#slider").slider( "value" );
然后滑块消失。
这是滑块执行计算的代码。这很有效,只是我不想一遍又一遍地设置 selection1 和 2。
任何想法为什么这不起作用?
var selection1;
var selection2;
$("#slider").slider({
range: "min",
value: 5000000,
min: 100000,
max: 10000000,
slide: function() {
selection1 = $("#slider").slider("value");
selection2 = $("#slider2").slider("value");
calcTmpl(selection1, selection2);
},
change: function() {
selection1 = $("#slider").slider("value");
selection2 = $("#slider2").slider("value");
calcTmpl(selection1, selection2);
}
});
$("#slider2").slider({
range: "min",
value: 50000,
min: 100,
max: 100000,
slide: function() {
selection1 = $("#slider").slider("value");
selection2 = $("#slider2").slider("value");
calcTmpl(selection1, selection2);
},
change: function() {
selection1 = $("#slider").slider("value");
selection2 = $("#slider2").slider("value");
calcTmpl(selection1, selection2);
}
});
calcTmpl(5000000,50000);