【问题标题】:Refresh other input fields when one of the fields is updated. Using Angularjs (Plunker attached)当其中一个字段被更新时,刷新其他输入字段。使用 Angularjs(附有 Plunker)
【发布时间】:2016-04-13 00:13:25
【问题描述】:

这里是笨蛋 http://plnkr.co/edit/Ll09uMtJEC0HqyGBRPjH?p=preview

正如在 plunker 中看到的,我有一个日期、用户和汽车作为输入字段。我可以选择日期、用户和汽车。

但是,如果我现在尝试更改日期,我希望用户和汽车应返回空白(不应显示任何值)

我怎样才能做到这一点。

<html>
</html>

【问题讨论】:

    标签: javascript angularjs html


    【解决方案1】:

    当日期改变时,你可以使用 ng-change 指令

    在您视图中日期的输入标签中:

    ng-change="clearInputFields()" 
    

    在你的控制器中:

    $scope.clearInputFields = function() { 
      $scope.params.car = "";
      $scope.params.user = {}; // or "" if it was a string
    }
    

    【讨论】:

    • 你打败了我。哈哈。
    【解决方案2】:

    您可以在日期选择器中使用ng-change。添加例如ng-change="resetvalue()"

    ng-change是在值变化时调用函数或做某事

    在函数resetvalue中

    $scope.resetvalue = function(){
      $scope.params.user = '';
      $scope.params.car = '';
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-20
      • 1970-01-01
      • 1970-01-01
      • 2016-10-13
      • 2016-08-02
      • 1970-01-01
      • 2022-11-27
      • 2012-05-11
      相关资源
      最近更新 更多