效果:
HTML部分:
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style type = "text/css">
@import"mystyle.css"
</style>
<script src="index.js" type="text/javascript"></script>
</head>
<body>
<div class= "test-css">
<form id = "form1" action="" method="post" class="STYLE-NAME" onsubmit = "return test()">
<h1>留言板实例
<span>填写下面的信息(*为必填).</span>
</h1>
<label>
<!-- <span id = "bt">*</span> -->
<span class = "c">ID :</span>
<input id="name" type="text" name="name" placeholder="填写你的ID" />
</label>
<label>
<!-- <span id = "bt">*</span> -->
<span class = "c">Email :</span>
<input id="email" type="email" name="email" placeholder="请输入有效的Email地址" />
</label>
<label>
<span>留言 :</span>
<textarea id="message" name="message" placeholder="请输入留言内容"></textarea>
</label>
<label>
<span>注册信息 :</span><select name="selection">
<option value="Job Inquiry">已注册用户</option>
<option value="General Question">游客</option>
</select>
</label>
<label>
<span> </span>
<input type="button" class="button" value="确定" οnclick= test() />
</label>
</form>
</div>
</body>
</html>
JS部分:
function test(){
e = email.value;
// i = name.value;
i = document.getElementById("name");
if (i == ""){
alert("ID不能为空!")
}
if (e == ""){
alert("邮箱不能为空!");
return false;
}
var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
ok = reg.test(e);
if (!ok){
alert("邮箱格式不正确!");
return false;
}
}
CSS部分:
.test-css {
margin-left:auto;
margin-right:auto;
max-width: 500px;
background: #F8F8F8;
padding: 30px 30px 20px 30px;
font: 12px Arial, Helvetica, sans-serif;
color: #666;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
}
.test-css h1{
font: 24px "Trebuchet MS", Arial, Helvetica, sans-serif;
padding: 20px 0px 20px 40px;
display: block;
margin: -30px -30px 10px -30px;
color: #FFF;
background: #9DC45F;
text-shadow: 1px 1px 1px #949494;
border-radius: 5px 5px 0px 0px;
-webkit-border-radius: 5px 5px 0px 0px;
-moz-border-radius: 5px 5px 0px 0px;
border-bottom:1px solid #89AF4C;
}
.test-css h1>span {
display: block;
font-size: 11px;
color: #FFF;
}
.test-css label {
display: block;
margin: 0px 0px 5px;
}
.test-css label>span {
float: left;
margin-top: 10px;
color: #5E5E5E;
}
.c::before{
content : "*";
color : red;
}
.test-css input[type="text"], .test-css input[type="email"], .test-css textarea, .stest-css select {
color: #555;
height: 30px;
line-height:15px;
width: 100%;
padding: 0px 0px 0px 10px;
margin-top: 2px;
border: 1px solid #E5E5E5;
background: #FBFBFB;
outline: 0;
-webkit-box-shadow: inset 1px 1px 2px rgba(238, 238, 238, 0.2);
box-shadow: inset 1px 1px 2px rgba(238, 238, 238, 0.2);
font: normal 14px/14px Arial, Helvetica, sans-serif;
}
.test-css textarea{
height:100px;
padding-top: 10px;
}
.test-css select {
background: no-repeat right, -moz-linear-gradient(top, #FBFBFB 0%, #E9E9E9 100%);
background: no-repeat right, -webkit-gradient(linear, left top, left bottom, color-stop(0%,#FBFBFB), color-stop(100%,#E9E9E9));
appearance:none;
-webkit-appearance:none;
-moz-appearance: none;
text-indent: 0.01px;
text-overflow: '';
width:100%;
height:30px;
}
.test-css.button {
background-color: #9DC45F;
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-border-radius: 5px;
border: none;
padding: 10px 25px 10px 25px;
color: #FFF;
text-shadow: 1px 1px 1px #949494;
}
.smart-green .button:hover {
background-color:#80A24A;
}