我有一个Kendo NumericTextBox。当某些某些字段具有某些特定值时,该NumericTextBox的值范围将只是奇数值。
如果当前值为奇数值,则设置步骤2将起作用。
因此,如果用户输入22之类的值并单击向上微调器,则应将值增加到23,然后在下次单击时增加25。
如果当前值为30且用户点击向下微调器,则应将值减小到29,然后在下次单击时减少27。
答案 0 :(得分:1)
以下是您的解决方案:http://jsfiddle.net/a6Ek2/8/
var numericTextBox = $("#bar").kendoNumericTextBox({
format: "d",
value: 1,
step: 2, }).data('kendoNumericTextBox');
numericTextBox.element.parent().find('.k-link').mousedown(function () {
var value = numericTextBox.value();
if (value % 2 === 0) {
if ($(this).find('span.k-icon').hasClass('k-i-arrow-n')) {
numericTextBox.value(value - 1);
}
else {
numericTextBox.value(value + 1);
}
} });
您也可以阻止从键盘输入数据并设置步骤2:
$("#foo").kendoNumericTextBox({
format: "d",
value: 1,
step: 2,
});
$("#foo").attr('readonly', true);
答案 1 :(得分:0)
这有点棘手,但可能会奏效。您应该使用step
将其设置为1或2,具体取决于数字文本字段的当前值。
然后在单击微调器或更改值时更改值。像这样:
function adjustStep() {
var value = this.value();
if (value % 2 == 1) {
number.options.step = 1;
} else {
number.options.step = 2;
}
}
var number = $("#numerictextbox").kendoNumericTextBox({
step : 1,
value : 21,
spin: adjustStep,
change: adjustStep
}).data("kendoNumericTextBox");
JSFiddle:http://jsfiddle.net/kF2h7/1/