【问题标题】:Why can't I enter text in input which is bind to angular model in Firefox?为什么我不能在与 Firefox 中的角度模型绑定的输入中输入文本?
【发布时间】:2018-04-16 15:18:39
【问题描述】:

我无法在 Firefox 中输入文本。相同的代码在 chrome 上运行良好。我没有遇到任何CSS问题。我没有使用 jquery。

下面是我的html代码

<div class="todo_content" style="width:66%">
  <input class="todo_add_input" autofocus="autofocus"
         placeholder="Please Add Task"  
         ng-model="addtask.activity_title" id="task-title">
</div>

渲染时,它会生成下面的 html 代码。

<div class="todo_content" style="width:66%">
  <input class="todo_add_input ng-pristine ng-valid ng-empty ng-touched" 
         autofocus="autofocus" placeholder="Please Add Task"
         ng-model="addtask.activity_title" id="task-title"
         aria-invalid="false" style="">
</div>

为什么,相同的代码在 Firefox 中不起作用?

【问题讨论】:

  • @RameshRajendran :您提供的第一个链接是基于 jquery 的。我已经要求 angularjs。我已经搜索了很多问题,但没有找到合适的解决方案。对于第二个链接,我的 Firefox 版本是最新的,我仍然面临这个问题。
  • @georgeawg:我没有遇到任何 CSS 问题。所有的 css 都正确应用了,除了我无法在文本框中输入文本!!
  • 分而治之。 一次删除一个属性,直到问题消失 - 然后添加最后一部分。这会让我们知道是哪个属性导致了问题。

标签: angularjs html firefox


【解决方案1】:

试试这个

使用指令

 app.directive('autoFocus', function($timeout) {
        return {
            restrict: 'AC',
            link: function(_scope, _element) {           
                    _element[0].focus();
            }
        };
    });

    <input name="theInput" auto-focus>

更多详情:How to set focus on input field?

【讨论】:

  • 尝试了您的解决方案,我删除了 html5 的 autofocus 属性并将此指令添加到我的应用程序中。对于 chrome,这有效,但对于 Firefox,它没有!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-13
  • 1970-01-01
  • 2020-04-17
  • 2018-10-31
  • 2013-12-14
  • 1970-01-01
  • 2014-12-08
相关资源
最近更新 更多