일부 연구를 한 후, 나는 Asp.net Ajax에서 Extend Web server control that encapsulates a client behavior
이라고 불렀다. 그리고 컴포넌트의 첨부 파일이 Asp.net에 의해 자동으로 수행된다는 것을 알았다. 우리는 Sys.Application.add_init(function()
코드가 자동으로 Asp.net에 의해 aspx 페이지에서 생성 된 것을 볼 수 있습니다. 따라서 Web Server Control의 원래 동작을 사용자 지정하려는 경우 Javascript OOP 방식 (이전 및 동일)으로 만들 수 있다고 생각합니다.
예 : 원래 동작 코드가 손상된 경우.
// Register the namespace for the control.
Type.registerNamespace('Samples');
//
// Define the behavior properties.
//
Samples.FocusBehavior = function(element) {
Samples.FocusBehavior.initializeBase(this, [element]);
this._highlightCssClass = null;
this._nohighlightCssClass = null;
}
//
// Create the prototype for the behavior.
//
Samples.FocusBehavior.prototype = {
initialize : function() {
Samples.FocusBehavior.callBaseMethod(this, 'initialize');
$addHandlers(this.get_element(),
{ 'focus' : this._onFocus,
'blur' : this._onBlur },
this);
this.get_element().className = this._nohighlightCssClass;
},
dispose : function() {
$clearHandlers(this.get_element());
Samples.FocusBehavior.callBaseMethod(this, 'dispose');
},
//
// Event delegates
//
_onFocus : function(e) {
if (this.get_element() && !this.get_element().disabled) {
this.get_element().className = this._highlightCssClass;
}
},
_onBlur : function(e) {
if (this.get_element() && !this.get_element().disabled) {
this.get_element().className = this._nohighlightCssClass;
}
},
//
// Behavior properties
//
get_highlightCssClass : function() {
return this._highlightCssClass;
},
set_highlightCssClass : function(value) {
if (this._highlightCssClass !== value) {
this._highlightCssClass = value;
this.raisePropertyChanged('highlightCssClass');
}
},
get_nohighlightCssClass : function() {
return this._nohighlightCssClass;
},
set_nohighlightCssClass : function(value) {
if (this._nohighlightCssClass !== value) {
this._nohighlightCssClass = value;
this.raisePropertyChanged('nohighlightCssClass');
}
}
}
// Optional descriptor for JSON serialization.
Samples.FocusBehavior.descriptor = {
properties: [ {name: 'highlightCssClass', type: String},
{name: 'nohighlightCssClass', type: String} ]
}
// Register the class as a type that inherits from Sys.UI.Control.
Samples.FocusBehavior.registerClass('Samples.FocusBehavior', Sys.UI.Behavior);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
나는 우리가 자바 스크립트 객체 Samples.FocusBehavior
의 메소드의 일부를 오버라이드 (override) 할 수 있다고 생각하고 그것을 사용자 정의를 달성하기 위해 프로토 타입 객체를합니다.
예를 들면.
이렇게 스크립트에서 Samples.FocusBehavior.prototype._onFocus
을 덮어 쓸 수 있습니다.
Samples.FocusBehavior.prototype._onFocus = function (e) {
alert('test');
if (this.get_element() && !this.get_element().disabled) {
this.get_element().className = this._highlightCssClass;
}
};
이 코드가 브라우저에서 원래 코드로 구문 분석되었는지 확인하십시오.
이것이 올바른 방법인지 확실하지 않습니다. 누군가가 그것을 확인하는 데 도움이되기를 바랍니다. 감사합니다.
여기에 tutorial입니다. 검토해주십시오. 건배.