【问题标题】:AngularJS input element focusAngularJS输入元素焦点
【发布时间】:2019-03-13 21:07:19
【问题描述】:

假设我的页面上有几个输入。一些单选按钮、一些复选框和输入类型=文本字段。我想要以下内容:在某些变量为真之前,我不想让用户关注 type=text 字段。 也许有一种解决方案,比如我们可以在数组中收集 input=text 字段,当用户关注一个时那些领域,不集中他们。谢谢。

Jsfiddle

这里是例子。在$scope.variableToEnableFocusOnInput 为假之前,我不希望$scope.inputValue 成为焦点。

【问题讨论】:

    标签: html angularjs input focus


    【解决方案1】:

    这个 ng-disabled 可能对您的情况有用。

    看看这个:https://docs.angularjs.org/api/ng/directive/ngDisabled

    那里也有很多例子,而且很容易学习和使用。

    我修改了你的这行代码,结果看起来像你问的那样。

    <input type="text" ng-disabled="!variableToEnableFocusOnInput" ng-model="inputValue">
    

    【讨论】:

    • 这是正确的解决方案,但对我来说不是。无论如何谢谢
    【解决方案2】:

    您可以使用一种简单的方法来做到这一点:-

    假设您不需要在选择复选框之前选择输入

      <form action="" name='checkForm'>
    <input required type='checkbox' ng-model='checkboxInput' name='checkboxInput'>
    <input type='text' ng-model='inputText' ng-disabled='checkForm.checkboxInput.$invalid'>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-27
      • 2017-04-24
      • 1970-01-01
      • 2014-10-27
      • 2015-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多