html5的Input Attr : Autofocus,感觉挺有意思的!
2014-03-11 19:05
381 查看
自动对焦的表单字段是一个布尔属性浏览器设置关注它当一个页面被加载。如果你还是不明白那是什么,请去谷歌,你注意到你只要输入搜索字符串不先点击文本框。
这是因为谷歌设置焦点,文本框自动(我不是说谷歌使用HTML5“自动对焦”)并保存你一个鼠标点击。
下面是代码,小菜一碟。
<label for="name">Your name goes here :</label><input id ="name" type="text" autofocus/> <br />
<label for="mothername">Your dog's name goes here :</label><input id ="mothername" type="text" />
“自动对焦”是一个布尔属性,设置任何值是不必要的。
像往常一样,并不是每一个web浏览器支持自动对焦”
实现多一点点简单的“自动对焦”,你将不得不再次使用Javascript来查看web浏览器是否支持“自动对焦”,如果不是,刚和Javascript设置焦点。
下面是演示以及测试。如果您的web浏览器支持自动对焦,你会发现光标闪烁在第一个文本框,如果浏览器不支持它,它将集中在第二个输入框。
<script>
function testAttribute(element, attribute) {
var test = document.createElement(element);
if (attribute in test) {
return true;
}
else
return false;
}
window.onload = function() {
if (!testAttribute('input', 'autofocus'))
document.getElementById('Text2').focus();
//for browser has no autofocus support, set focus to Text2.
}
</script>
<label for="Text1">Support Autofocus :</label><input id ="Text1" type="text" autofocus/> <br />
<label for="Text2">No Autofocus Support :</label><input id ="Text2" type="text" />
这是因为谷歌设置焦点,文本框自动(我不是说谷歌使用HTML5“自动对焦”)并保存你一个鼠标点击。
下面是代码,小菜一碟。
<label for="name">Your name goes here :</label><input id ="name" type="text" autofocus/> <br />
<label for="mothername">Your dog's name goes here :</label><input id ="mothername" type="text" />
“自动对焦”是一个布尔属性,设置任何值是不必要的。
像往常一样,并不是每一个web浏览器支持自动对焦”
实现多一点点简单的“自动对焦”,你将不得不再次使用Javascript来查看web浏览器是否支持“自动对焦”,如果不是,刚和Javascript设置焦点。
下面是演示以及测试。如果您的web浏览器支持自动对焦,你会发现光标闪烁在第一个文本框,如果浏览器不支持它,它将集中在第二个输入框。
<script>
function testAttribute(element, attribute) {
var test = document.createElement(element);
if (attribute in test) {
return true;
}
else
return false;
}
window.onload = function() {
if (!testAttribute('input', 'autofocus'))
document.getElementById('Text2').focus();
//for browser has no autofocus support, set focus to Text2.
}
</script>
<label for="Text1">Support Autofocus :</label><input id ="Text1" type="text" autofocus/> <br />
<label for="Text2">No Autofocus Support :</label><input id ="Text2" type="text" />
相关文章推荐
- Oracle ASM的AU(Allocation Units)
- AutoLayout中的Content Hugging 和 Content Compression Resistance
- AU3软件自动化安装教程
- rk3288+10bit AU 屏dual lvds 屏调试曲折
- Alsa period_size/periods/buffer_size计算逻辑
- html5的Input Type : Range,大家都知道这个是怎么样的吗?
- html5的Input Type : Date,大家知道怎么去用这个吗?
- 宣传部第六次培训总结
- Adobe au 修改语言设置
- html5Web表单2.0,其实,真的是比较是有趣的哦
- html5烟花绽放效果
- HTML5高级编程之像素处理及粒子效果
- 分享8款令人惊叹的HTML5 Canvas动画特效
- html5通信方式
- html5画布的一些应用,感觉还是挺不错的,呵呵!
- html5本地存储
- Canvas的Path分享,又一个html5知识点哦!
- html5一些知识点Canvas : Shadow,大家可以看下!
- 简单的html5布局
- 10款功能强大的HTML5/CSS3应用插件