您好我想獲得一個「UpDown」按鈕,允許用戶按住遞增/遞減按鈕來快速輕鬆地遞增/遞減十進制值。我一直在嘗試使用ajaxToolkit:NumericUpDownExtender,但這似乎只允許按鈕點擊增加/減少。由於價值是一個百分比,因此這很笨拙。任何想法更好的方式來處理這在ASP.NET內?帶按鈕保持支持的ASP.NET NumericUpDownExtender?
2
A
回答
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);
}
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最後一個擴展程序將處理鼠標按鈕保持。
相關問題
- 1. OnClickListener保持按鈕?
- 2. SpriteKit按鈕保持按下
- 3. 按按鈕保持時間
- 4. Flash後退按鈕支持
- 5. 保持焦點的按鈕
- 6. Ajax NumericUpDownExtender按鈕佈局
- 7. 保持狀態按鈕Android
- 8. win32按鈕保持閃爍
- 9. 保持聲音對按鈕
- 10. WinForm按鈕保持焦點
- 11. 按鈕保持在MouseDown中
- 12. 保持按鈕在Red5Phone
- 13. Paypal支付語言支持按鈕
- 14. 不支持HTML和Javascript的按鈕
- 15. 與前進/後退按鈕的支持
- 16. jQuery的標籤支持後退按鈕
- 17. jQuery手機按鈕保持按下
- 18. 如何保持按鈕按下
- 19. 電源按鈕按下 - 保持屏幕
- 20. ASP.NET 5 MySQL支持
- 21. Asp.Net Mvc:ListBoxFor()支持OptionGroups?
- 22. 帶HTML支持的IconItemRenderer
- 23. 帶SSL支持的Jetty ProxyServlet
- 24. 帶VS2012的OpenCV(Qt支持)
- 25. 帶NULL支持的QComboBox
- 26. 「後退按鈕」 - 原生支持ajax
- 27. Android支持設計浮動按鈕
- 28. Google Plus按鈕API支持Internet Explorer 8
- 29. 支持在amp-html中分享按鈕
- 30. 如何使用後退按鈕支持創建ASP.NET MVC嚮導?
這個鏈接可以幫助你..嗎? http://www.c-sharpcorner.com/blogs/1372/up-down-extender-in-asp-net.aspx – MethodMan 2013-05-09 21:36:40
謝謝,但似乎並沒有顯示如何使這個控制按鈕按住。我希望用戶能夠按住鼠標左鍵來使值連續變化。 – flerngobot 2013-05-09 21:51:00
你可以顯示一些代碼,也許你可以做你自己的自定義keydown事件 – MethodMan 2013-05-09 22:12:31