เมื่อเรากรอกข้อมูลช่องใดเสร็จก็จะบอก % การกรอกเสร็จ ต้องกรอกจนครบ 100% จึงจะกดปุ่ม submit ได้
โค้ด
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>jQuery Percent Completion Meter</title>
<style type="text/css">
#container {position:relative; width:990px; margin:0 auto;}
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
(function($){
$.fn.percentComplete = function(selector, color, size, button){
return this.each(function(){
var fieldCount = $(selector).length;
var completeCount = $(selector+'[value != ""][value != "select"]').length;
var percentComplete = Math.round((completeCount / fieldCount) * 100);
$(this).empty().append(percentComplete + "% Complete<br><div><div> </div></div>").children("div").css({"width": size, "border": "1px solid"+color}).children("div").css({"width": percentComplete+"%", "background-color":color});
if(percentComplete == '100'){
$(button).attr('disabled',false);
}else{
$(button).attr('disabled',true);
}
});
};
})(jQuery);
$("document").ready(function(){
$("#submit").attr('disabled',true);
$("#completion_meter").percentComplete(".required", "#000000", "200px", "#submit");
$(":input").blur(function(){
$("#completion_meter").percentComplete(".required", "#000000", "200px", "#submit");
});
});
</script>
</head>
<body>
<div id="container">
<br><br>
<div id="completion_meter"></div>
<br><br>
<form>
<div>First Name: <input class="required" id="first_name" name="first_name" type="text" value=""/></div>
<div>Last Name: <input class="required" id="last_name" name="first_name" type="text" value=""/></div>
<div>Email: <input class="required" id="email" name="email" type="text" value="" /></div>
<div>Birthday: <input class="required" id="Birthday" name="birthday" type="text" value="" /></div>
<div>Address: <input class="required" id="address" name="address" type="text" value="" /></div>
<div>Do you like Tech Crunch: <select class="required" id="tech_crunch"><option value="select">select</option><option value="yes">yes</option><option value="no">no</option></select></div>
<div>Description:<br><textarea rows="6" cols="40" class="required" name="description" id="description"></textarea></div>
<input type="submit" name="submit" id="submit" value="submit" />
</form>
</div>
</body>
</html>
ไม่มีความคิดเห็น:
แสดงความคิดเห็น