【发布时间】:2017-02-24 19:35:41
【问题描述】:
我在 html 文件中编写了下面的脚本。
我在类 firstNameInputEditor 中附加了带有 firstName.change 函数和一个更新函数的文本框的更改事件,我在创建类 firstNameInputEditor 的实例后扩展了该函数。
现在的问题是当更改事件被调用时,我的更新函数没有被调用。
我想创建不同的 firstNameInputEditor 实例,它可以有不同的更新函数实现。并且这个更新函数应该在 change 函数内部调用。
请帮忙
<html>
<head>
<title>
User Resgistration for
</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0/prototype.js"></script>
</head>
<body>
<form id ="myForm">
First Name <input type="text" id = "firstName" onchange = "firstName.change(event)"/></br>
</form>
<script type="text/javascript">
var firstNameInputEditor = Class.create({
initialize: function(id) {
this.elementId = id;
this.elementId.onchange = this.change;
},
update :function(event){
console.log('outside update', event);
},
change : function(event){
this.update(event);
console.log('change update', event);
}
});
var firstName = new firstNameInputEditor($('firstName'));
firstName.update = function(event){
console.log('new update' + event);
}
</script>
</body>
</html>
【问题讨论】: