⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numericupdownbehavior.js

📁 AJAX 应用 实现页面的无刷新
💻 JS
📖 第 1 页 / 共 2 页
字号:
        /// <returns />
        
        // Use toFixed/parseFloat to prevent quantization when incrementing
        var tmp = parseFloat((this._currentValue + step).toFixed(Math.max(this._stepPrecision, this._valuePrecision)));
        if (step > 0) {
            this._currentValue = Math.max(Math.min(tmp, this._max), this._min);
        } else {
            this._currentValue = Math.min(Math.max(tmp, this._min), this._max);
        }        
    },
    
    _computePrecision : function(value) {
        /// <summary>
        /// Compute the precision of the value by counting the number
        /// of digits in the fractional part of its string representation
        /// </summary>
        /// <param name="value" type="Number">Value</param>
        /// <returns type="Number" integer="true">
        /// Fractional precision of the number
        /// </returns>
    
		if (value == Number.Nan) {
			return this._min;
		}

        // Call toString which does not localize, according to ECMA 262
		var str = value.toString();
		if (str) {
			var fractionalPart = /\.(\d*)$/;
			var matches = str.match(fractionalPart);
			if (matches && matches.length == 2 && matches[1]) {
				return matches[1].length;
			}
		}

		return this._min;
    },

    get_Width : function() {
        /// <value type="Number" integer="true">
        /// Combined size of the TextBox and Up/Down buttons (min value 25).
        /// This property is not used if you provide custom buttons.
        /// </value>
        return this._widthValue;
    },
    set_Width : function(value) {
        if (this._widthValue != value) {
            this._widthValue = value;
            this.raisePropertyChanged('Width');
        }
    },
    
    get_Tag : function() {
        /// <value type="String">
        /// Specifies a custom parameter to pass to the Web Service
        /// </value>
        return this._tagValue;
    },
    set_Tag : function(value) {
        if (this._tagValue != value) {
            this._tagValue = value;
            this.raisePropertyChanged('Tag');
        }
    },
    
    get_TargetButtonUpID : function() {
        /// <value type="String">
        /// Reference to a custom Up button
        /// </value>
        return this._targetButtonUpIDValue;
    },
    set_TargetButtonUpID : function(value) {
        if (this._targetButtonUpIDValue != value) {
            this._targetButtonUpIDValue = value;
            this.raisePropertyChanged('TargetButtonUpID');
        }
    },
    
    get_TargetButtonDownID : function() {
        /// <value type="String">
        /// Reference to a custom Down button
        /// </value>
        return this._targetButtonDownIDValue;
    },
    set_TargetButtonDownID : function(value) {
        if (this._targetButtonDownIDValue != value) {
            this._targetButtonDownIDValue = value;
            this.raisePropertyChanged('TargetButtonDownID');
        }
    },
    
    get_ServiceUpPath : function() {
        /// <value type="String">
        /// Path to a web service that returns the data used to get the next value.
        /// If empty, a PageMethod will be used instead of a web service.
        /// </value>
        return this._serviceUpPathValue;
    },
    set_ServiceUpPath : function(value) {
        if (this._serviceUpPathValue != value) {
            this._serviceUpPathValue = value;
            this.raisePropertyChanged('ServiceUpPath');
        }
    },
    
    get_ServiceUpMethod : function() {
        /// <value type="String">
        /// Name of the method to call on the web service (or the name of a PageMethod) to get the next value
        /// </value>
        /// <remarks>
        /// The signature of the web method must be of the form:
        ///     [WebMethod]
        ///     public int MethodName(int current, string tag)
        ///     {
        ///         ...
        ///     }
        /// </remarks>
        return this._serviceUpMethodValue;
    },
    set_ServiceUpMethod : function(value) {
        if (this._serviceUpMethodValue != value) {
            this._serviceUpMethodValue = value;
            this.raisePropertyChanged('ServiceUpMethod');
            if (this._elementTextBox)
                this._elementTextBox.readOnly = true;
        }
    },
    
    get_ServiceDownPath : function() {
        /// <value type="String">
        /// Path to a web service that returns the data used to get the previous value.
        /// If empty, a PageMethod will be used instead of a web service.
        /// </value>
        return this._serviceDownPathValue;
    },
    set_ServiceDownPath : function(value) {
        if (this._serviceDownPathValue != value) {
            this._serviceDownPathValue = value;
            this.raisePropertyChanged('ServiceDownPath');
        }
    },
    
    get_ServiceDownMethod : function() {
        /// <value type="String">
        /// Name of the method to call on the web service (or the name of a PageMethod) to get the previous value
        /// </value>
        /// <remarks>
        /// The signature of the web method must be of the form:
        ///     [WebMethod]
        ///     public int MethodName(int current, string tag)
        ///     {
        ///         ...
        ///     }
        /// </remarks>
        return this._serviceDownMethodValue;
    },
    set_ServiceDownMethod : function(value) {
        if (this._serviceDownMethodValue != value) {
            this._serviceDownMethodValue = value;
            this.raisePropertyChanged('ServiceDownMethod');
            if (this._elementTextBox)
                this._elementTextBox.readOnly = true;
        }
    },
    
    get_RefValues : function() {
        /// <value type="String">
        /// A list of strings separated by semicolons (;) to be used as an enumeration
        /// </value>
        return this._refValuesValue ? this._refValuesValue.join(";") : "";
    },
    set_RefValues : function(value) {
        if (value != '') {
            this._refValuesValue = value.split(';');
            this._onChange();
            if (this._elementTextBox) {
                this._elementTextBox.readOnly = true;
            }
        } else {
            this._refValuesValue = null;
            if (this._elementTextBox) {
                this._elementTextBox.readOnly = false;
            }
        }
        this.raisePropertyChanged('RefValues');
    },
    
    get_Step : function() {
        /// <value type="Number">
        /// Step used for simple numeric incrementing and decrementing
        /// </value>
        return this._step;
    },
    set_Step : function(value) {
        if (value != this._step) {
            this._step = value;
            this._stepPrecision = this._computePrecision(value);
            this.raisePropertyChanged('Step');
        }
    },
        
    get_Minimum : function() {
        /// <value type="Number">
        /// Minimum Value
        /// </value>
        return this._min;
    },
    set_Minimum : function(value) {
        if (value != this._min) {
            this._min = value;
            this.raisePropertyChanged('Minimum');
        }
    },
    
    get_Maximum : function() {
        /// <value type="Number">
        /// Maximum Value
        /// </value>
        return this._max;
    },
    set_Maximum : function(value) {
        if (value != this._max) {
            this._max = value;
            this.raisePropertyChanged('Maximum');
        }
    },

    _clickUp : function(evt) {
        /// <summary>
        /// Handler for the Up button's click event
        /// </summary>
        /// <param name="evt" type="Sys.UI.DomEvent" mayBeNull="true" >
        /// Event info
        /// </param>

        this.readValue();
        //Proxy WebService
        if (this._serviceUpPathValue && this._serviceUpMethodValue) {
            // Call the helper web service
            Sys.Net.WebServiceProxy.invoke(this._serviceUpPathValue, this._serviceUpMethodValue, false,
                { current:this._currentValue, tag:this._tagValue },
                Function.createDelegate(this, this._onMethodUpDownComplete));
            $common.updateFormToRefreshATDeviceBuffer();
        } else {
            //Else increment one element on _refValues or juste this._currentValue++
            if (this._refValuesValue) {
                if ((this._currentValue + 1) < this._refValuesValue.length) {
                    this._currentValue = this._currentValue + 1;
                    this.setCurrentToTextBox(this._refValuesValue[this._currentValue]);
                }
            } else {
                this._incrementValue(this._step);
                this.setCurrentToTextBox(this._currentValue);
            }
        }
        if (evt) {
            evt.preventDefault();
        }        
        return false;
    },    
    
    _clickDown : function(evt) {
        /// <summary>
        /// Handler for the Down button's click event
        /// </summary>
        /// <param name="evt" type="Sys.UI.DomEvent" mayBeNull="true">
        /// Event info
        /// </param>

        this.readValue();
        //Proxy WebService
        if (this._serviceDownPathValue && this._serviceDownMethodValue) {
            // Call the helper web service
            Sys.Net.WebServiceProxy.invoke(this._serviceDownPathValue, this._serviceDownMethodValue, false,
                { current:this._currentValue, tag:this._tagValue },
                Function.createDelegate(this, this._onMethodUpDownComplete));
            $common.updateFormToRefreshATDeviceBuffer();                
        } else {
            //Else decrement one element on _refValues or juste this._currentValue--
            if (this._refValuesValue) {
                if ((this._currentValue - 1) >= 0) {
                    this._currentValue = this._currentValue - 1;
                    this.setCurrentToTextBox(this._refValuesValue[this._currentValue]);
                }
            } else {
                this._incrementValue(-this._step);
                this.setCurrentToTextBox(this._currentValue);
            }
        }    
        if (evt) {
            evt.preventDefault();
        }        
        return false;
    },
    
    //Call BackWebServices
    _onMethodUpDownComplete : function(result, userContext, methodName) {
        this._currentValue = result;
        this.setCurrentToTextBox(this._currentValue);
    }
}
AjaxControlToolkit.NumericUpDownBehavior.registerClass('AjaxControlToolkit.NumericUpDownBehavior', AjaxControlToolkit.BehaviorBase);
//    getDescriptor : function() {
//        var td = AjaxControlToolkit.NumericUpDownBehavior.callBaseMethod(this, 'getDescriptor');

//        td.addProperty('Width', Number);        
//        td.addProperty('TargetButtonUpID', String);
//        td.addProperty('TargetButtonDownID', String);
//        td.addProperty('ServiceUpPath', String);
//        td.addProperty('ServiceUpMethod', String);
//        td.addProperty('ServiceDownPath', String);
//        td.addProperty('ServiceDownMethod', String);
//        td.addProperty('RefValues', String);
//        td.addProperty('Tag', String);
//        td.addEvent('CurrentChanged', true);
//        return td;
//    },

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -