我第一次調用container.slider(...)時只是獲得了正確的外觀。我如何解決它?動態調用JQuery Slider並沒有正確更新它的值
更新 - 很明顯,演示是一個快速黑客再現問題,讓我們不選擇使用全球變量等,除非它涉及到問題。
攝製(按幾次按鈕):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html style="height: 100%;">
<head>
<title></title>
<link href="styles/themes/ui-lightness/jquery-ui-1.9.0.custom.min.css" rel="stylesheet"
type="text/css" />
<script src="scripts/external/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="scripts/external/jquery-ui-1.9.0.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
//
var longValues = [10, 50, 90];
var shortValues = [50];
var mode;
function setLong() {
$("#c").slider({ orientation: "horizontal", range: false, values: longValues, min: 0, max: 100, step: 1 });
mode = "long";
}
function setShort() {
$("#c").slider({ orientation: "horizontal", range: false, values: shortValues, min: 0, max: 100, step: 1 });
mode = "short";
}
$("#t").on("click", function() {
if (mode == "long") {
console.log("set short");
setShort();
}
else {
console.log("set long");
setLong();
}
});
setLong();
});
</script>
</head>
<body style="height: 100%;">
<div id="c" style="width: 200px; vertical-align: middle;">
</div>
<button id="t">Toggle
</button>
</body>
</html>
你是不是想添加和刪除兩個把手的點擊按鈕時? – adeneo 2013-02-22 15:27:04
不,我想在同一個容器中渲染不同的滑塊。 – user1514042 2013-02-22 15:31:46
好吧,這裏是你怎麼做 - > [** FIDDLE **](http://jsfiddle.net/qAweP/)... – adeneo 2013-02-22 15:33:21