javascript - ng-blur 只有在文本框内单击时才有效

标签 javascript angularjs

我有一个文本框,可以在其中写入一个值。如果我删除该值并且不在适当的位置写入任何内容,我希望当我单击其他地方时该值在文本框中“返回”。

有些东西可以工作,但不完全是应该的。

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/

相关文章:

javascript - 如何启动这个 Node.JS 应用程序?

javascript - Angular 2 中 select 的更改事件在 Firefox 和 Edge 中不起作用

javascript - angularJs - 不同结构的两种不同模型是否可以同步或共享状态?

javascript - 如何使用 AngularJS $filter 在 Controller 中订购 JSON 数据

angularjs - angular ui-grid 如何在 gridOptions 中使用 onRegisterApi

css - 我应该在 Protractor 中使用什么定位器?

javascript - 纯CSS制作下拉列表

javascript - 切换项目数组中单个项目的图标

javascript - 删除元素,替换其他地方的元素

基于 JavaScript 文本的宠物游戏