我在 javascript 对象的属性中为 keyup 事件赋值。它在控制台中打印 null 。
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();
}
})}
}
身体
<div class="first">
<input type="text" id="val_00_01" />
</div>
<div class="two">
<input type="text" id="val_00_02"/>
</div>
<script type="text/javascript">
var first= new check('.first');
var two= new check('.two');
first.touch()
two.touch()
</script>