gpt4 book ai didi

javascript - jQuery focus() 不聚焦

转载 作者:行者123 更新时间:2023-11-28 16:46:00 25 4
gpt4 key购买 nike

我对 jQuery focus() 有疑问。从选择器中,我可以定位元素,并且可以更改元素的 css(例如 display:none)。但是使元素成为焦点是行不通的。
一个视频demo .打开高清看得更清楚。
我使用 AngularJs 进行显示。

我正在做的事情很难解释。演示 here
可以找到代码here

如何使用该应用程序:单击表单的第一个文本字段。将生成一个新表单。如您所见,当生成新表单时,第一个输入字段将获得焦点。接下来您在新表单中选择第二个选择字段,选择下拉列表或选项。然后你点击第一个输入框,会生成一个新的表单。我这里的问题是它不关注新的。

我如何专注:

$scope.addSubItem = function(index)
{
var newSubItem = [];
var data = $scope.inputData;
newSubItem.push("");
newSubItem.push(0);
newSubItem.push("hour");
newSubItem.push("");
$scope.items[index][6].push(newSubItem);
var itemToBeFocus = "#subItem" + index +"form:last-child input:first-child";
setTimeout(function(){
$(itemToBeFocus).focus(); //here
},0);
}


最佳答案

我猜你在 "form 之前错过了一个 _ 空格:

var itemToBeFocus = "#subItem" + index +" form:last-child input:first-child";
angular.element(itemToBeFocus).focus(); //here

而不是 setTimeout 尝试使用 angular.element() jqLit​​e 对象包装器。

关于javascript - jQuery focus() 不聚焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33170057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com