在我的应用程序中,我使用jquery-ui
slider 。用户可以将 slider 的值从 1(月)更改为 60(月)。实际上1-60是几个月。根据11之后的新要求, slider 的值应更改为1(年)、2(年)等。我担心的是,我可以有这种改变值测量的 slider 吗?如果是,请举例说明。
这是我的来源。
$(".slider").slider({
animate: true,
range: "min",
value: 1,
min: 1,
max: 60,
step: 1
});
最佳答案
虽然这不可能开箱即用,
我在这里为你制作了一个工作 fiddle http://jsfiddle.net/JFJKP/
HTML:
<div class="slider"></div>
<br/>
<div class='showAltValue'>Click to Show Alt Value</div>
JS:
$(".slider").slider({
animate: true,
range: "min",
value: 1,
min: 1,
max: 60,
altValue: 'Nothing Selected',
step: 1,
change: function (event, ui) {
value = ui.value;
years = Math.floor(value / 12);
months = value % 12 // value modulus of 12 gives remainder
if (years > 1) {
yearString = 'years';
} else {
yearString = 'year';
}
if (months > 1 && months != 0) {
monthString = 'months';
} else {
monthString = 'month';
}
// Now format the output.
if (years == 0) {
altValue = months + ' ' + monthString;
} else {
if (months == 0) {
//dont' show months
altValue = years + ' ' + yearString;
} else {
altValue = years + ' ' + yearString + ' ' + months + ' ' + monthString;
}
}
// Now alert the altValue
alert(altValue);
// You can now use this as a label Value somewhere and even store it as a slider attribute as such
$(event.target).slider("option", "altValue", altValue);
}
});
$('.showAltValue').click(function () {
alert($('.slider').slider("option", "altValue"));
});
这至少应该让您走上正确的道路。
关于javascript - jquery-ui slider 变化值测量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19632352/