使用 Zend Form 专注于 Textarea

发布于 2025-01-02 07:21:23 字数 177 浏览 2 评论 0原文

我已经使用 Zend Form 构建了一个表单,并且希望在页面加载时将焦点放在表单内的文本区域上。我尝试使用 JS,有时它会显示焦点半秒,但在实际输入任何内容之前它会删除焦点。

我认为 Zend Form 可能会阻止焦点,所以我查了一下,发现了自动对焦属性选项,但这也无济于事。

知道可能是什么问题吗? 谢谢

I've build a form with Zend Form, and would like the focus to be on a text area inside the form on page load. I tried with JS, sometimes it shows the focus for half a second, but it removes the focus before one can actually type anything.

I thought Zend Form may prevents the focus, so i looked it up, and found the autofocus attrib-option, but that won't help either.

Any idea what the matter may be?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓦然回首 2025-01-09 07:21:23

自动对焦似乎工作正常,但 IE 不支持它。所以你现在可能还停留在 JavaScript 上。

我在 Firefox 和 IE 中测试了自动对焦,使用方法:

$element->setAttrib('autofocus', 'autofucus');

它在 2 文档类型的 Firefox 中运行良好。 HTML5 和 XHTML1.0

我还没有在这种情况下尝试过,但是将 HTML5 shim 放入标头中似乎可以使 IE 表现得更好。

<!--[if IE]><script type="text/javascript" src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

autofocus seems to work fine, however it is not supported in IE. So you're likely stuck with javascript for now.

I tested autofocus in firefox and IE using:

$element->setAttrib('autofocus', 'autofucus');

it work well in firefox with 2 doctypes. HTML5 and XHTML1.0

I haven't tried it in this context but putting the HTML5 shim in your header seems to make IE behave much better.

<!--[if IE]><script type="text/javascript" src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
檐上三寸雪 2025-01-09 07:21:23

如果您使用过 dojo getFocusOnLoad() 可能有助于在页面加载时设置焦点。

请访问以下链接:

If you have used dojo getFocusOnLoad() might help to set the focus when the a page loads..

Please follow these links:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文