struts2 返回html文本,HTML自动聚焦不能用作Struts2文本字段属性(HTML autofocus does not work as a Struts2 textfield attri...

这篇博客讨论了在Struts2框架下,HTML的autofocus属性无法直接用于文本字段的问题。作者提到,尽管按照Autofocus的相关答案,理论上可以设置焦点,但在实际生成的HTML中,autofocus并未生效。为了解决这个问题,提出了在JSP或外部JS文件中使用jQuery脚本来手动设置焦点的方法。此外,还提到了Struts2框架中的一些其他相关技术细节和最佳实践。
摘要由CSDN通过智能技术生成

HTML自动聚焦不能用作Struts2文本字段属性(HTML autofocus does not work as a Struts2 textfield attribute)

在我看来,根据Autofocus的答案,下面的代码应该将焦点设置在imageName div上。

但是自动对焦不会出现在生成的html中。

I appears to me that according to the answer at Autofocus the following code should set the focus on the imageName div.

But the autofocus does not appear in the generated html.

原文:https://stackoverflow.com/questions/41968079

更新时间:2020-09-13 19:09

最满意答案

由于struts2标记lib不支持autoFocus attrribue,因此您可以在此处使用解决方法。

在JSP或外部JS文件中,您可以添加此jQuery脚本。

$( function(){

$( '#imageName ).focus();

} );

As the autoFocus attrribue is not supported by struts2 tag lib you can use workaround here.

In the JSP or in the external JS file you can add this jQuery script.

$( function(){

$( '#imageName ).focus();

} );

相关问答

如果要从i18n资源获取字段标签,请使用label属性和getText方法实际从资源中检索值。

label="%{getText('lbl.commandType.' + #type.getLabel())}" />

或者使用而不是getText 。

然后Struts2将在您的堆栈中迭代以查找具有属性xxx的对象,即具有公共方法getXxx() 。 Struts2将当前操作( SampleAction一个实例)放在堆栈顶部。 因此,它将首先搜索SampleAction.getXxx()方法 - 如果没有找到,它将在堆栈中向下看。 (实际上你可以将其他对象放在堆栈中,在Action之上

...

不知道如何在做到这一点,因为从未在struts2标签中看到过libor没有遇到它。 将使用简单的标签 假设我们将listmap作为map

继续阅读那些遇到类似问题的人。 http://fellowtuts.com/jquery/jquery-focus-not-working-in-chrome/ Answering the edited part of my question. Below code fixed chrome browser issue

...

每个请求实例化Struts 2操作。 当您点击showCategorie URL时,新实例化的操作中没有数据,因此无需显示任何内容。 如果你想保留你需要的价值,你可以将它保存在某个地方,例如数据库,会话,应用程序等。 Struts 2 actions are instantiated per-request. There is no data in the newly-instantiated action, hence nothing to display, when you hit the s

...

在Struts2中,当您需要重新填充bean项列表时,需要通过索引来引用它们。 请参考以下示例: Bean类: public class Person {

private int id;

private String name;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public Str

...

修复。 发现了这个问题。 它与jsp文件中使用的JScript有关。 发生这种情况是因为在jsp上写的JS在重新加载或访问页面时正在擦除输入字段值。经验教训,有时JS可能是罪魁祸首。 :) Fixed it. Found the issue. It was related to JScript used in the jsp file. This occured because JS written on the jsp was erasing input field value when pag

...

你正在使用哪个主题? 由于size是struts2 text-field的有效参数。 我建议你做以下步骤: 使用简单的主题:

label="Username" id="un1" size="20"/>

...

由于struts2标记lib不支持autoFocus attrribue,因此您可以在此处使用解决方法。 在JSP或外部JS文件中,您可以添加此jQuery脚本。 $( function(){

$( '#imageName ).focus();

} );

As the autoFocus attrribue is not supported by struts2 tag lib you can use workaround here. In the JSP or in the

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值