`
leonzhx
  • 浏览: 794269 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

A Form of Madness

 
阅读更多

1.   Placeholder text is displayed inside the input field as long as the field is empty. When you click on (or tab to) the input field and start typing, the placeholder text disappears. Here’s how you can include placeholder text in your own web forms:

<form>

  <input name="q" placeholder="Go to a Website">

  <input type="submit" value="Search">

</form>
 

Browsers that don’t support the placeholder attribute will simply ignore it. No harm, no foul. The placeholder attribute can only contain text, not HTML markup.

 

 

2.   When you press the space bar expecting to scroll the page, the page will not scroll if the focus is already in a form input field due to site’s autofocus script. (It types a space in the field instead of scrolling.) If you focus a different input field while the page is still loading, the site’s autofocus script may “helpfully” move the focus back to the original input field, disrupting your flow and causing you to type in the wrong place. HTML5 introduces an autofocus attribute on all web form controls. The autofocus attribute does exactly what it says on the tin: as soon as the page loads, it moves the input focus to a particular input field. But because it’s just markup instead of script, the behavior will be consistent across all web sites.

 

3.   If you want your autofocus fields to work in all browsers, not just these fancy-pants HTML5 browsers, you can do this:

<form name="f">

  <input id="q" autofocus>

  <script>

    if (!("autofocus" in document.createElement("input"))) {

      document.getElementById("q").focus();

    }

  </script>

  <input type="submit" value="Go">

</form>
 

The window.onload event doesn’t fire until after all your images have loaded. Placing the auto-focus script immediately after the form field that it references is the optimal solution. If you can’t insert a script in the middle of your page, you should set focus during a custom event like jQuery’s $(document).ready() instead of window.onload .

 

 

4.   HTML5 defines 13 new field types, the first of these is for email address:

<form>

  <input type="email">

  <input type="submit" value="Go">

</form>
 

Every single browser on Earth treats an unknown type attribute as type="text" — even IE 6. The HTML5 specification doesn’t mandate any particular user interface for the new input types. Most desktop browsers simply render it as a text box. Apple did something clever in the iPhone’s web browser. It recognizes several of the new HTML5 input types, and dynamically changes the on-screen keyboard to optimize for that kind of input. When you use an iPhone and focus an <input type="email"> element, you get an on-screen keyboard that contains a smaller-than-usual space bar, plus dedicated keys for the @ and . characters.

 

 

5.   The iPhone altered its virtual keyboard when you focus an <input type="url"> . The space bar has been completely replaced with three virtual keys: a period(. ), a forward slash, and a “.com ” button. (You can long-press the “.com ” button to choose other common suffixes like “.org ” or “.net ”.) Most modern desktop browsers simply render type="url" like a regular text box.

 

6.   HTML5 has provided a powerful number input:

 

<input type="number"

       min="0"

       max="10"

       step="2"

       value="6"> 
 

min="0" specifies the minimum acceptable value for this field. max="10" is the maximum acceptable value. step="2" , combined with the min value, defines the acceptable numbers in the range: 0, 2, 4, and so on, up to the max value. value="6" is the default value. The default step value is 1. You also get these handy JavaScript methods as well:

  a)   input.stepUp(n) increases the field’s value by n .

  b)   input.stepDown(n) decreases the field’s value by n .

  c)   input.valueAsNumber returns the current value as a floating point number. (The input.value property is always a string.)

On the iPhone, the browser optimizes the virtual keyboard for numeric input. In the desktop version of Opera, the same type="number" field is rendered as a “spinbox” control.

 

7.   You can now have slider controls in your web forms:

 

<input type="range"

       min="0"

       max="10"

       step="2"

       value="6"> 
 

All the available attributes are the same as type="number" .The only difference is the user interface. Instead of a field for typing, browsers are expected to render type="range" as a slider control.

 

8.   HTML5 finally defines a way to include a native date picker control without having to script it yourself. In fact, it defines six: date, month, week, time, date + time, and date + time - timezone.

 

9.   If you’re using Safari on Mac OS X, the input box for type=”search” has rounded corners. When you actually start typing into the type="search" box, Safari inserts a small “x ” button on the right side of the box. Clicking the “x ” clears the contents of the field.

 

10.   HTML5 also defines <input type="color"> , which lets you pick a color and returns the color’s hexadecimal representation.

 

11.  W hen the user tries to submit a form with an <input type="email"> field, the browser automatically offers RFC -compliant email validation, even if scripting is disabled. HTML5 also offers validation of web addresses entered into <input type="url"> fields, and numbers in <input type="number"> fields. The validation of numbers even takes into account the min and max attributes, so browsers will not let you submit the form if you enter a number that is too large. To turn it off, use the novalidate attribute:

<form novalidate>

  <input type="email" id="addr">

  <input type="submit" value="Subscribe">

</form> 
 

 

12.   You can also specify that certain fields are required. Required fields must have a value before you can submit the form:

 

<form>

  <input id="q" required>

  <input type="submit" value="Search">

</form> 
 
分享到:
评论

相关推荐

    Flash游戏——疯狂射手(Stickman Madness)

    《疯狂射手》(Stickman Madness)是一款基于Flash技术开发的在线射击游戏,以其独特的故事情节和挑战性深受玩家喜爱。在这个游戏中,玩家扮演的角色不再是传统意义上的英雄,而是一位勇敢的女主角,她的任务是营救被...

    Roller Madness.zip

    这包括减少多边形数量、优化光照、使用LOD(Level of Detail)层次细节系统,以及合理利用资源加载和卸载机制。 通过深入研究和实践“Roller Madness”这个Unity3D示例项目,开发者不仅能掌握游戏开发的基本技能,...

    zoj 3531 Alice Madness Return.md

    zoj 3531 Alice Madness Return.md

    基于Java的MadNess项目.zip

    基于Java的MadNess项目 项目简介 MadNess项目是一个基于Java的NCAA季后赛括号赛管理系统,专注于管理玩家、队伍、比赛和数据集。通过使用Apache Derby数据库,项目实现了数据的初始化、管理、编辑和展示。 主要...

    march_madness_pickem-源码.rar

    【标题】"march_madness_pickem-源码.rar" 暗示这是一个与“疯狂三月”(March Madness)相关的项目,March Madness通常指的是美国大学篮球联赛NCAA的年度锦标赛。源码可能是一个应用程序或网站,允许用户进行比赛...

    NBA Madness-crx插件

    nba madness - 主页 通过安装nba madness,您将获得来自NBA联赛的社交媒体,新闻和实时分数,加上Web搜索,100%免费在您的Chrome新建 标签扩展。 “替换您在打开新标签时看到的页面” 这允许我们向您展示我们的...

    RPG Madness-开源

    我们希望将来能制作几款游戏,并且一直在寻找新的团队成员。

    MM2021:March Madness BracketWeb抓取

    【标题】"MM2021:March Madness BracketWeb抓取" 涉及的是一个使用Python进行网络数据抓取的项目,特别是针对体育赛事中“三月疯狂”(March Madness)篮球比赛的赛程支架(Bracket)信息的抓取。在体育竞技中,尤其...

    Madness:递归下降到疯狂

    递归下降到疯狂疯狂是一种Swift µframework,用于解析简单的无上下文语法中的字符串。 组合来自简单Swift表达式的解析器并进行... 有关使用Madness进行解析的一些示例,请参见Madness.playground 。采用乐兴Madness

    「WEB应用防火墙」Mobile MFA Madness Mobile Device Hygiene and MFA In

    「WEB应用防火墙」Mobile MFA Madness Mobile Device Hygiene and MFA Integrity Challenges - 工控安全 信息安全 漏洞分析 WAF 安全意识 系统安全

    madness:即时降价服务器

    $ alias madness= ' docker run --rm -it -v $PWD:/docs -p 3000:3000 dannyben/madness ' 设计意图Madness的设计目的是为了轻松浏览,查看和搜索基于markdown的本地文档目录。 功能亮点易于使用。 内置全文本搜索...

    R in Action 2nd 原版PDF by Kabacoff

    When I began writing this book, I spent quite a bit of time searching for a good quote to start things off. I ended up with two. R is a wonderfully flexible platform and language for exploring, ...

    信息安全_数据安全_Mobile MFA Madness Mobile Device.pdf

    首先,标题“信息安全_数据安全_Mobile MFA Madness Mobile Device.pdf”揭示了文档将围绕信息安全和数据安全展开讨论,并专门关注移动设备上的多因素认证问题。标题中的“Mobile MFA Madness”表达了一种对当前移动...

    Madness-开源

    多智能体分布式SANE系统的学术项目

    gmail-madness

    介绍 此存储库包含一个脚本mbox2es.py ,该脚本采用包含电子邮件集合的 .mbox 格式文件,并将其索引到在 localhost:9200 上运行的 elasticsearch 实例到索引mail 。 它还包含一个脚本gmvault2es.py ,该脚本采用工具...

    madness:一个用于Tokio的异步Mdns库

    "madness" 是一个专为 Tokio 设计的异步 Mdns 库。Mdns,即 Multicast DNS,是一种基于 DNS 协议的本地网络服务发现技术,它允许设备在无需集中式 DNS 服务器的情况下进行服务发现和通信。Tokio 是一个用于构建异步...

    ar-madness:ARKit游戏

    该仓库包含AR Madness的代码,这是一个ARKit游戏,您可以在其中拍摄像浴盆和鲨鱼这样的愚蠢事物,以及像香蕉和斧头这样的愚蠢事物! 我们最初在都柏林为Coder Dojo Coolest Projects 2018构建了游戏,并决定将代码...

    Kaggle-March-Madness-Machine-Learning-2018:Kaggle机器学习竞赛提交的March Madness 2018

    Kaggle March Madness机器学习2018 描述 Google Cloud和NCAA:registered:联手为您带来了今年的Kaggle机器学习竞赛版本。 再过一年,又有一次机会可以预料到烦恼,打电话给概率以及将方括号论技能用于排行榜测试。 ...

    March_Madness_2021:March Madness数据准备和算法创建,用于猜测给定年份的March Madness中排名前10的团队

    《疯狂三月数据分析:预测March Madness的顶尖球队》 在篮球界,每年的三月份,全美大学篮球联赛(NCAA)都会举行一场名为“疯狂三月”(March Madness)的淘汰赛,吸引着全世界篮球迷的目光。在这个项目中,我们将...

Global site tag (gtag.js) - Google Analytics