是否有任何纯html属性来指定哪个元素应该关注负载 [英] Is there any pure-html attribute to specify which element should be focused on load

查看:145
本文介绍了是否有任何纯html属性来指定哪个元素应该关注负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有,是否有充分的理由?

这是HTML的一部分5,所以在以前的版本缺乏可能是更多的监督或其他选择降低优先级的情况下。



如果您好奇,语法将如下所示:

 < input type =textname =abcvalue =autofocus> 

按照标准,只能在页面上声明一次。



与此同时,在国家的状态下,只能在onload事件中通过脚本来实现。最简单的方法是,在页面上分配一个默认的元素一致的ID(称之为自动对焦),然后总是将其设置为:

  var a_focus = document.getElementById('autofocus'); 
if(a_focus)a_focus.focus();

希望有帮助。


And if there isn't, is there a good reason why?

解决方案

This is coming as a part of HTML 5, so the lack of it in prior version is probably more of an oversight or a case of there being other options lowering the priority.

If you're curious, the syntax will be something like:

<input type="text" name="abc" value="" autofocus>

By the standard, it must only be declared once on a page.

In the meanwhile, with the state of the nation, you can only really do it with script in the onload event. The easiest way, is to assign the default element on the page a consistent id (call it 'autofocus') and then always set it like:

var a_focus = document.getElementById('autofocus');
if(a_focus) a_focus.focus();

Hope that helps.

这篇关于是否有任何纯html属性来指定哪个元素应该关注负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆