angular.js - angularjs 显示textarea后如何自动获取焦点
大家讲道理
大家讲道理 2017-05-15 17:06:42
0
1
527

{{x.placeholder}}

由ng-repeat生成了多个这样的结构,textarea一开始隐藏,点击lc-hint,使textarea出现,如何自动获取焦点。

官方文档里的setfocus指令好像不行。求助

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all (1)
大家讲道理

There is something wrong with your code:

ng-click="toEdit({{$index}})"

should be written as

ng-click="toEdit($index)"

Why not use the native one and add the id of textarea to abc;

document.getElementById("abc").focus();

If you input in the console, it is best to add a delay. The focus of textarea can only be triggered when the current page is in focus state. After typing, click anywhere on the page immediately to trigger:

setTimeout(function(){document.getElementById("abc").focus();},1000);

The setfocus you encounter does not take effect, it may be because the current page is not in focus.

Put it in your code environment, add textarea with id, the prefix I wrote is suibianla_{whatever}:

$scope.toEdit = function(index){ //你的业务代码 inputContent[index].readable = true; //我猜你是这样写的,在这里后边加一句 document.getElementById("suibianla_" + index).focus(); }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!