我有一个文本框,可以在其中写入一个值。如果我删除该值并且不在适当的位置写入任何内容,我希望当我单击其他地方时该值在文本框中“返回”。
有些东西可以工作,但不完全是应该的。
HTML 部分:
<input type="number" ng-blur="$ctrl.blur('max')"
ng-change="$ctrl.updateY('max')" ng-model-options="{debounce: 500}"
ng-model="$ctrl.max">
JS部分:
blur(which) {
if(which === 'max') {
if(!this.max) {
this.max = this.maxValue;
}
}
}
updateY(which) {
if(which === 'max') {
if(this.max) {
this.maxValue = this.max;
}
}
const maxNumber = Number(this.maxValue);
this.lineView.chart.axis.range({max: {y: maxNumber}, min: {y: maxNumber-100}});
}
就像现在一样,如果我删除文本框的值并单击屏幕上的其他位置,该值不会写回到文本框中。
但是如果我删除它后点击文本框,它会被写回。即使我点击文本框外的任何地方,我也想让它被重写。
这可能吗?
最佳答案
我还可以看到“奇怪”的行为,因为它只是有时发生而不是一直发生。 要解决此问题,请删除
ng-model-options="{debounce: 500}"
它会起作用的。
关于javascript - ng-blur 只有在文本框内单击时才有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48763389/