您好我正在尝试获得一个“UpDown”按钮,该按钮允许用户按住递增/递减按钮以快速轻松地递增/递减十进制值。我一直在尝试使用 ajaxToolkit:NumericUpDownExtender 但这似乎只允许通过单击按钮进行递增/递减。这相当笨拙,因为该值是百分比。关于在 ASP.NET 中处理此问题的更好方法的任何想法?
问问题
1013 次
2 回答
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);
}
于 2013-05-11T17:47:03.163 回答
0
将此脚本的引用添加到 ScriptManager 控件的 Script 集合:
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 演示最后一个扩展程序将处理鼠标按钮保持。
于 2013-05-11T19:04:22.057 回答