function check(id){
var me= this;
this.ID= null;
this.matchName= this.ID.substr(this.ID.lastIndexOf('_'));
this.first= function(){
alert(me.matchName)
}
this.second= function(){
alert(1)
}
this.touch= function(){
$(id).find('input').keyup(function(e){
me.ID= this.id;;
if(e.keyCode==13){
id.indexOf('first')>-1? me.first(): me.second();
}
})}
}
음이 하나 개의 깨진 부분 (이것은 의도적 아니라면?)
이 속성에 액세스
this.ID= null;
시도를 null로 ID 속성을 설정 당신 null와 동등하게 설정된다
this.matchName= this.ID.substr(this.ID.lastIndexOf('_'));
이 코드는 Check 클래스의 초기화 (생성자)에서 실행 중이며 오류가 발생합니다.
는 여기에 내가 눈 출혈을 일으킬 그렇게하지 않는 것이 좋습니다 서식, 당신이 원하는 무슨 생각입니다.
// capitalize first letter of class name
function Check(className){ // use a prop/descriptive parameter name
var me = this; // set your variable "me" to class instanced
this.ID = null; // INITIALIZE your ID and matchName variables
this.matchName = null;
this.first = function(){
alert(me.matchName)
};
this.second = function(){
alert(1)
};
this.touch = function(){
// get the element with class=className
// find the input inside of it
// set an onkeyup handler to the input element
$(className).find('input').keyup(function(e){
me.ID = this.id;; // set the ID variable to the INPUT element's ID property
// set matchName to the last part of the input's ID property
// matchName will be "01" or "02" in this case
me.matchName = this.ID.split("_")[this.ID.split("_").length - 1];
if(e.keyCode==13){
id.indexOf('first') > -1 ? me.first(): me.second();
}
});
};
}
...
var first = new Check('.first');
var two = new Check('.two');
first.touch();
two.touch();
질문을하고 코드를 포맷하는 것을 잊었습니다. – MightyPork
코드가 깨지는 위치 또는 작동 할 때의 시나리오를 제공하지 않았습니다. – NoLifeKing