您好我正在尝试使用“UpDown”按钮,该按钮允许用户按住递增/递减按钮以快速轻松地递增/递减小数值。我一直在尝试使用ajaxToolkit:NumericUpDownExtender,但这似乎只允许按钮点击增加/减少。这是相当笨重的,因为价值是一个百分比。有没有想过在ASP.NET中处理这个问题的更好方法?
答案 0 :(得分:1)
我能够使用计时器简单地使用javascript。 这是ASPX的一部分:
<asp:TextBox ID="Factor" runat="server" MaxLength="6" Width="60"/>
<input id ="UpButton" value="▲" type="button" onmousedown="timerID = setInterval(function(){FactUp()},100);" onmouseup="clearInterval(timerID);"/>
<input id ="DownButton" value="▼" type="button" onmousedown="timerID = setInterval(function(){FactDown()},100);" onmouseup="clearInterval(timerID);"/>
和javascript:
var timerID = 0;
function FactDown() {
var obj = document.getElementById('Factor');
var num = parseFloat(obj.value)
if (isNaN(num)) {
return;
}
num -=0.01;
obj.value = num.toFixed(2);
}
function FactUp() {
var obj = document.getElementById('Factor');
var num = parseFloat(obj.value);
if (isNaN(num)) {
return;
}
num += 0.01;
obj.value = num.toFixed(2);
}
答案 1 :(得分:0)
将此脚本的引用添加到ScriptManager控件的脚本集合中:
Sys.Extended.UI.NumericUpDownBehavior.prototype._clearClickInterval = function () {
if (this._clickInterval != null) {
window.clearInterval(this._clickInterval);
this._clickInterval = null;
}
};
Sys.Extended.UI.NumericUpDownBehavior.prototype._setDownClickInterval = function () {
this._clearClickInterval();
this._clickInterval = window.setInterval(this._clickDownHandler, 200);
};
Sys.Extended.UI.NumericUpDownBehavior.prototype._setUpClickInterval = function () {
this._clearClickInterval();
this._clickInterval = window.setInterval(this._clickUpHandler, 200);
};
Sys.Extended.UI.NumericUpDownBehavior.prototype.addIntervalHandlers = function () {
this._clickInterval = null;
this._buttonMouseUpHandler = Function.createDelegate(this, this._clearClickInterval);
if (this._bUp) {
this._upButtonMouseDownHandler = Function.createDelegate(this, this._setUpClickInterval);
$addHandler(this._bUp, 'mousedown', this._upButtonMouseDownHandler);
$addHandler(window, 'mouseup', this._buttonMouseUpHandler);
}
if (this._bDown) {
this._downButtonMouseDownHandler = Function.createDelegate(this, this._setDownClickInterval);
$addHandler(this._bDown, 'mousedown', this._downButtonMouseDownHandler);
$addHandler(window, 'mouseup', this._buttonMouseUpHandler);
}
};
var legacyInitialize = Sys.Extended.UI.NumericUpDownBehavior.prototype.initialize,
legacyDispose = Sys.Extended.UI.NumericUpDownBehavior.prototype.dispose;
Sys.Extended.UI.NumericUpDownBehavior.prototype.initialize = function () {
legacyInitialize.apply(this);
this.addIntervalHandlers();
};
Sys.Extended.UI.NumericUpDownBehavior.prototype.dispose = function () {
legacyDispose.apply(this);
this._clearClickInterval();
if (this._upButtonMouseDownHandler) {
$removeHandler(this._bUp, 'mousedown', this._upButtonMouseDownHandler);
$removeHandler(window, 'mouseup', this._buttonMouseUpHandler);
this._upButtonMouseDownHandler = null;
}
if (this._downButtonMouseDownHandler) {
$removeHandler(this._bDown, 'mousedown', this._downButtonMouseDownHandler);
$removeHandler(window, 'mouseup', this._buttonMouseUpHandler);
this._downButtonMouseDownHandler = null;
}
this._buttonMouseUpHandler = null;
};
不确定,但可能需要在扩展程序实例上明确地调用addIntervalHandlers()
函数。
如果您要在此行末尾添加$find("ctl00_SampleContent_NumericUpDownExtender4").addIntervalHandlers()
并在此页面上的浏览器控制台中执行此操作,则可以检查此脚本:NumericUpDown Demonstration最后一个扩展程序将处理鼠标按钮。