//html代码
<input type="text" class="input-name" onblur="checkname()" onfocus="clearname()">
//js代码
<script>
function checkname(){
var name = $('.input-name').val();
if(name == ""){
$('.input-name').val('请输入姓名').css('color','#de2525');
}
}
function clearname(){
var name = $('.input-name').val();
if(name == "请输入姓名"){
$('.input-name').val('').css('color','#000')
}
}
function checkcompany(){
var name = $('.input-company').val();
if(name == ""){
$('.input-company').val('请输入公司名称').css('color','#de2525');
}
}
function clearcompany(){
var name = $('.input-company').val();
if(name == "请输入公司名称"){
$('.input-company').val('').css('color','#000');
}
}
function checkemail(){
var email = $('.input-email').val();
if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!= -1)
return true;
else
$('.input-email').val('请输入正确邮箱').css('color','#de2525')
}
function clearemail(){
var email = $('.input-email').val();
if(email == "请输入正确邮箱"){
$('.input-email').val('').css('color','#000');
}
}
function checkmobile(){
var mobile = $('.input-mobile').val();
var num = /^1\d{10}$/ ;
if(num.test(mobile)) {
return true;
}else {
$('.input-mobile').val('请输入正确的手机号').css('color','#de2525');
}
}
function clearmobile(){
var mobile = $('.input-mobile').val();
if(mobile == "请输入正确的手机号"){
$('.input-mobile').val('').css('color','#000');
}
}
function checkquestion(){
var question = $('.input-question').val();
if(question == ""){
$('.input-question').val('请输入您的需求').css('color','#de2525');
}
}
function clearquestion(){
var question= $('.input-question').val();
if(question == "请输入您的需求"){
$('.input-question').val('').css('color','#000');
}
}
</script>
网友评论