Forms

*/-->

Forms

1 Displaying a Search Input Field

You want to present a user with a search form field.

<form>
 <p><label>Search <input type="search" name="query"></label></p>
 <p><button type="submit">Submit</button></p>
</form>
input[type="search"]{
    border-radius:10px;
}

2 Contact Information Input Fields

You want to present a user with a form to provide contact information, such as an email address, a URL, and a telephone number.
Use the input element with HTML5 type with email,url,and tel.

<form>
   <fieldset>
   <legend>Contact Information</legend>
    <p><label>E-mail address <input type="email" name="email"></label></p>
    <p><label>Web site <input type="url" name="website"></label></p>
    <p><label>Telephone number <input type="tel" name="phone"></label></p>
  </fieldset>
<p><button type="submit">Submit</button></p>
</form>

It can warn you if you enter a invaild email or url.

3 Utilizing Date and Time Input Fields

You want to provide a user with a form to specify a date and/or time—for example,when scheduling an appointment.

<fieldset>
  <legend>Appointment Request</legend>
  <p><label>Date <input type="date" name="date" min="2011-03-15"
                        max="2012-03-14"></label></p>
  <p><label>Time <input type="time" name="time" min="08:00"
                        max="18:00"></label></p>
</fieldset>

4 Number Inputs

input type is number.

 <p><label>Quantity <input type="number" name="quantity"></label></p>
<p><label>Quantity (must order in pairs of 2) <input type="number"
name="quantity" min="2" max="20" step="2"></label></p>

5 Selecting from a Range of Numbers

You want to present a user with a form to select a number from a range—for example, to adjust the volume on a video.

<form>
<p><label>Volume <input type="range" name="volume"
min="0" max="10" step=".5" value="5"></label></p>
</form>

6 Selecting Colors

<form>
   <p><label>Background color <input type="color" name="bg"></label></p>
   <p><label>Foreground color <input type="color" name="fg"></label></p>
</form>

7 Creating an Editable Drop-Down

You want to give the user the ability to enter text but also prompt her with some suggestions to choose from. This is sometimes known as an editable drop-down or a combo box.

<form>
  <p><label>Donation amount <input type="text" name="donation" list="donations"></label></p>
  <datalist id="donations">
  <option value="10.00">10.00</option>
  <option value="25.00">25.00</option>
  <option value="50.00">50.00</option>
</datalist>

8 Requiring a Form Field

You want to require a form field’s completion prior to form submission.

<form>
<fieldset>
<legend>Login</legend>
<p><label>Username <input type="text" name="username" required></label></p>
<p><label>Password <input type="password" name="pwd" required></label></p>
</fieldset>
<p><button type="submit">Submit</button></p>
</form>

9 Autofocusing a Form Field

You want to place the focus in a particular form field when a page loads.

<form>
<p><label>Search <input type="search" name="query" autofocus></label></p>
<p><button type="submit">Submit</button></p>
</form>

10 Displaying Placeholder Text

You want to display some hint or help text within a form field.

<form>
<fieldset>
<legend>Contact Information</legend>
<p><label>E-mail address <input type="email" name="email"
placeholder="[email protected]"></label></p>
<p><label>Web site <input type="url" name="website"
placeholder="http://www.domain.com/"></label></p>
<p><label>Telephone number <input type="tel" name="phone"
placeholder="123-123-1234"></label></p>
</fieldset>
<p><button type="submit">Submit</button></p>
</form>

11 Disabling Autocomplete

You want to prevent autocompletion tools from populating a form field.

<form>
<fieldset>
<legend>Login</legend>
<p><label>Username <input type="text" name="username"></label></p>
<p><label>Password <input type="password" name="pwd"
autocomplete="off"></label></p>
</fieldset>
<p><button type="submit">Submit</button></p>
</form>

12 Restricting Values

You want to restrict the value of an input field according to a set of rules you specify.Use the HTML5 pattern attribute to specify a regular expression that will be used tovalidate the user’s input:

<form>
<p><label>Telephone number <input type="tel" name="phone"
pattern="[2-9][0-9]{2}-[0-9]{3}-[0-9]{4}"
title="North American format: XXX-XXX-XXXX"></label></p>
<p><button type="submit">Submit</button></p>
</form>

13 Making HTML5 Work in Older Browsers

You want to make HTML5 input types and attributes work in browsers that do not support HTML5. Use the Modernizr JavaScript library (see http://www.modernizr.com) to detect support for specific HTML5 attributes, then develop or use alternate solutions, such as jQuery UI (see http://jqueryui.com), for instances where features are not supported.

<head>
<script src="modernizer.js"></script>
</head>

<form>
<p><label>Search <input type="search" name="query" id="query"
autofocus></label></p>
<p><button type="submit">Submit</button></p>
</form>
<script>
if (!Modernizr.input.autofocus) {
document.getElementById("query").focus();
}
</script>

14 Validating Form Data in Older Browsers with JavaScript

You want to validate form data in browsers that do not support HTML5.

<script>
if (!Modernizr.input.required || !Modernizr.input.pattern) {
$(‘form‘).submit(function() {
var validData = true;
$(‘[required], [pattern]‘).each(function() {
if (($(this).attr(‘required‘) !== false) && ($(this).val() == "")){
$(this).focus();
alert("The " + $(this).attr(‘name‘) + " field is required!");
validData = false;
return false;
}
if ($(this).attr(‘pattern‘)){
var regexp = new RegExp($(this).attr(‘pattern‘));
if (!regexp.test($(this).val())){
$(this).focus();
alert("The data in the " + $(this).attr(‘name‘) +
" field isn‘t in the right format!");
validData = false;
return false;
}
}
});
return validData;
});
}
</script>

Author: mlhy

Created: 2015-10-10 六 16:17

Emacs 24.5.1 (Org mode 8.2.10)

时间: 2024-10-18 02:20:47

Forms的相关文章

Catch Application Exceptions in a Windows Forms Application

You need to handle the System.Windows.Forms.Application.ThreadException event for Windows Forms. This article really helped me: http://bytes.com/forum/thread236199.html. Application.ThreadException += new ThreadExceptionEventHandler(MyCommonException

菜鸟的Xamarin.Forms前行之路——原生Toast的简单实现方法

项目中信息提示框,貌似只有个DisplayAlert,信息提示太过于单一,且在有些场合Toast更加实用,以下是一个简单的原生Toast的实现方法 项目地址:https://github.com/weiweu/TestProject/tree/dev/Toast 共享项目 定义一个接口IToast,包括Short和Long两个方法: public interface IToast { void LongAlert(string message); void ShortAlert(string m

张高兴的 Xamarin.Forms 开发笔记:为 Android 与 iOS 引入 UWP 风格的汉堡菜单 ( MasterDetailPage )

所谓 UWP 样式的汉堡菜单,我曾在"张高兴的 UWP 开发笔记:汉堡菜单进阶"里说过,也就是使用 Segoe MDL2 Assets 字体作为左侧 Icon,并且左侧使用填充颜色的矩形用来表示 ListView 的选中.如下图 但怎样通过 Xamarin.Forms ,将这一样式的汉堡菜单带入到 Android 与 iOS 中呢? 一.大纲-细节模式简介 讲代码前首先来说说这种导航模式,官方称"大纲-细节模式"(MasterDetail).左侧的汉堡菜单称为&qu

菜鸟的Xamarin.Forms前行之路——绪言

作者入门时间不是很久,差不多一年,期间自学的东西比较杂乱,到目前为止,编程方面的知识比较薄弱.之所以做这个系列,也只是因为做了两个月的Xamarin.Forms方面的东西,由于资料和自身实力的原因,过程走的比较艰难,但所幸的是也解决了部分的问题,积累了一些经验.期望通过这个系列,和大家分享经验,查漏纠错. 作为一个菜鸟,在解决问题的时候,往往比较直接,就是仅仅为了解决问题,期间可能根本没有考虑性能等方面的问题.所以在这个系列中,问题肯定是作者亲身实践能够解决的,但是在性能资源等方面作者没有做过考

Xamarin.Forms开发APP

Xamarin.Forms+Prism(1)-- 开发准备 准备: 1.VS2017(推荐)或VS2015: 2.JDK 1.8以上: 3.Xamarin.Forms 最新版: 4.Prism 扩展,打开VS的扩展和更新,在联机中,搜索Prism,安装第一个扩展Prism Template Pack: 5.Android SDK,这个下载已经非常快了,国内已经支持Android环境下载. 6.都准备好后,请确保创建一个新的Xamarin.Forms程序后,能正常调试运行,不能调试运行的,请百度或

asp.net权限认证:Forms认证

摘要: 明天就除夕了,闲着也是闲着,特地总结一些关于.net下的权限认证的方法. 一.Forms认证示意图 Forms认证即是表单认证,需提供身份id和密码password的进行认证和授权管理. 应该是大家比较熟悉的一种,刚接触.net可能都会学学这个东西. 下面看看他的工作方式: 二.看图太乏味,我准备了一个demo 因为默认首页为:IndexController/Index,这个页面只要一行字 “Index”, 效果图: OK,页面没有做任何权限控制,显示正常. 接下来看看DefaultCo

DotNetBar for Windows Forms 14.0.0.3_冰河之刃重打包版原创发布

关于 DotNetBar for Windows Forms 14.0.0.3_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版---------------------------------------------------------基于 官方原版的安装包 + http://www.cnblogs.com/tracky 提供的补丁DLL制作而成.安装之后,直接就可以用了.省心省事.不必再单独的打一次补丁包了.本安装包和补丁包一样都删除了官方自带

Displaying Window In Center In Oracle Forms 6i

Center window automatically  in Oracle Forms 6i, use the following procedure by passing window name as parameter: Example PROCEDURE auto_centre (pwn in varchar2) ISvw number := get_window_property(forms_mdi_window, width);vh number := get_window_prop

Using GET_APPLICATION_PROPERTY in Oracle D2k Forms

Using GET_APPLICATION_PROPERTY in Oracle D2k Forms DescriptionReturns information about the current Form Builder application. You must call the built-in once for eachvalue you want to retrieve.Usage NotesTo request a complete login, including an appe

Writing On-Error Trigger In Oracle Forms

Suppose you want to handle an error in oracle forms and want to display custom error message for that error, but also you want to customize more for a particular error. For example there are many fields in form with required property is set to TRUE f