每次我使用此函数时,我都会得到 this.refresh() 不是错误日志中的函数,但它工作正常。
另外,当我第一次点击这个函数时,this.value=undefined。当我在此表单和所有其他表单中再次单击该函数时,该值会很好地填充以前的值。
我可能做错了什么?
如何更有效地编写这个函数?
我仍然不太明白如何使用 this.value 在数组中捕获和存储值。
function askGender(x) {
response = "<select class=widgetstyle onClick=_setGender(this.value)><option value=Female>Female<option value=Male>Male</select>";
characters[x].setGender(response);
if (this.gender != 0) {
response = this.gender;
this.gender = 0;
characters[x].setGender(response);
}
}
function _setGender(x) {
this.gender = x;
this.refresh();
}
最佳答案
response = "<select class=widgetstyle onClick=_setGender(this.value)><option value=Female>Female<option value=Male>Male</select>";
看看你的回复。您可以在点击处理程序中设置性别。你对如何的误解this
有效。
this
在askGender
指的是你的 Angular 色对象。当 onClick 处理程序被调用时this
将引用 setGender
中的 DOM 对象方法。
备案.refresh
是他的Character对象的一个方法。
整个代码很大,需要彻底调试。看起来您正在编辑开源代码并尝试以非设计用途的方式使用它。
关于javascript - 该函数可以工作,但报告 this.refresh() 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4837628/