求html前段开发案例

html-css08

求html前段开发案例,第1张

/*

***这是我前两天帮别人写的表单验证例子,主要还是html的部分,里面用了一点点Bootstrap的东西,希望能帮到你

*/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=utf-8" />

<title>雇员注册表单demo</title>

<!-- 新 Bootstrap 核心 CSS 文件 -->

<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->

<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->

<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>

</head>

<body>

<div class="container" style="margin-top: 30pxmargin-bottom: 30px">

<div class="col-xs-12" style="width:90%margin-left: 5%">

<div class="col-xs-12" style="background: rgb(116, 146, 112)color: #ffffont-weight: boldpadding-left: 10pxpadding-right: 10pxheight: 60pxpadding-top: 10px">

<div class="col-xs-3"><hr/></div>

<div class="col-xs-6" style="font-size: 24pxtext-align: centerpadding-top:2px">雇员注册表单</div>

<div class="col-xs-3"><hr/></div>

</div>

<div class="col-xs-12" style="background: #F3F3F3font-size:1em">

<div class="col-xs-12" style="margin-top:20px">

<div class="col-xs-4" style="text-align: right">雇员编号</div>

<div class="col-xs-8"><input type="text" id="numbers"></div>

</div>

<div class="col-xs-12" style="margin-top:10px">

<div class="col-xs-4" style="text-align: right">雇员姓名</div>

<div class="col-xs-8"><input type="text" id="name"></div>

</div>

<div class="col-xs-12" style="margin-top:10px">

<div class="col-xs-4" style="text-align: right">雇员工作</div>

<div class="col-xs-8"><textarea rows="3" cols="20" id="work"></textarea></div>

</div>

<div class="col-xs-12" style="margin-top:10px">

<div class="col-xs-4" style="text-align: right">雇佣日期</div>

<div class="col-xs-8"><input type="date" id="time"></div>

</div>

<div class="col-xs-12" style="margin-top:10px">

<div class="col-xs-4" style="text-align: right">基本工资</div>

<div class="col-xs-8"><input type="text" id="wages"></div>

</div>

<div class="col-xs-12" style="margin-top:10px">

<div class="col-xs-4" style="text-align: right">奖金</div>

<div class="col-xs-8"><input type="text" id="bonus"></div>

</div>

<div class="col-xs-12" style="margin-top: 30pxmargin-bottom: 50pxtext-align: center">

<button style="background: rgb(116, 146, 112)width:120pxheight: 40pxborder: 0px nonefont-weight: boldcolor:#fff" id="button">提交表单</button>

</div>

</div>

</div>

</div>

</body>

<script>

$("#button").on('click',function(){

var $numbers = $('#numbers').val(),

$name = $('#name').val(),

$work = $('#work').val(),

$time = $('#time').val(),

$bonus = $('#bonus').val(),

$wages = $('#wages').val()

if(isNaN($numbers)){

alert("编号只能是数字")

return

}

if($name == '' || $name.length == 0){

alert("姓名不能为空")

return

}

if($work == '' || $work.length == 0){

alert("工作不能为空")

return

}

if(!isNaN($bonus)){

var dot = $bonus.indexOf(".")

if(dot != -1){

var dotCnt = $bonus.substring(dot+1,$bonus.length)

if(dotCnt.length != 2 ){

alert("必须满足小数点后两位")

return

}

}

}else{

alert("必须为数字")

return

}

if(!isNaN($wages)){

var dot = $wages.indexOf(".")

if(dot != -1){

var dotCnt = $wages.substring(dot+1,$wages.length)

if(dotCnt.length != 2 ){

alert("必须满足小数点后两位")

return

}

}

}else{

alert("必须为数字")

return

}

})

</script>

</html>

HTML 表单用于搜集不同类型的用户输入。

实例

文本域 (Text field)

本例演示如何在 HTML 页面创建文本域。用户可以在文本域中写入文本。

密码域

本例演示如何创建 HTML 的密码域。

(可以在本页底端找到更多实例。)

表单

表单是一个包含表单元素的区域。

表单元素是允许用户在表单中(比如:文本域、下拉列表、单选框、复选框等等)输入信息的元素。

表单使用表单标签(<form>)定义。