【问题标题】:Angular X-editable set focus eventAngular X 可编辑设置焦点事件
【发布时间】:2016-02-10 16:58:06
【问题描述】:

我正在使用angular-xeditable api。你能告诉我当表单“加载”并按下“添加行”按钮时如何将焦点设置为控件吗?

JsFiddle

在上面的api上有一个名为$activate(name)的方法。但是我不知道如何在上面的场景中使用它。谢谢。

 // add user
  $scope.addUser = function() {
    $scope.users.push({
      id: $scope.users.length+1,
      name: '',
      status: null,
      group: null,
      isNew: true
    });
  };

【问题讨论】:

    标签: javascript angularjs x-editable


    【解决方案1】:

    这是一个fiddle,我想出什么来解决你的问题。

    我在 addUser 方法中添加了一个 setFocus 函数调用

        $timeout( function() { 
            $scope.setFocus('name', $scope.users.length - 1); 
        }, 50);
    
        $scope.setFocus = function (id, index) {
            angular.element( document.querySelectorAll("#" + id))[index].focus(); 
        };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-26
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-12
      • 2015-07-21
      相关资源
      最近更新 更多