如何根据特定条件聚焦列表视图中的列表项?

How to focus the list items in the list view based on certain conditions?

我的页面中有一个列表视图,其中包含页面加载时的项目列表,我需要根据用户在表单提交时在文本字段中的搜索来关注列表中的列表项目..任何人都可以帮助我有了这个?

你没有告诉我们什么样的 HTML 元素应该是 focused - 正常的 divs/spans 或像 input 这样的形式元素s.

如果你需要聚焦一个普通元素,即突出它,那么你只需要 CSS 装饰它。您可以通过以下方式执行此操作:

listItem.add(AttributeModifier.append("style", "border: 1px red solid", ";"));

listItem.add(AttributeModifier.append("class", "myHighlightClass", " "));

以上将为 ListView 的 HTML 元素添加 CSS styleclass 属性 wicket:id

如果您需要聚焦 HTML input/select 元素,那么您需要像 $('#yourInputId').focus() 一样执行 JavaScript。 您可以在 Wicket 的 #renderHead(IHeaderResponse response) 方法中完成:

response.render(OnDomReadyHeaderItem.forScript("$('#" + textField.getMarkupId() + "').focus()"));