我希望设置一个具有进度条的表单,同时用户填写输入字段。我已经从教程和在线设置了我所知道的一切,但它没有用。
请查看是否有人能弄明白为什么它不起作用。
它保存在这里 - > http://jsfiddle.net/VbP4w/
这是示例JS代码
$("#form input").keyup(function() {
var numValid = 0;
$("#form input[required]").each(function() {
if (this.validity.valid) {
numValid++;
}
});
var progress = $("#progress"),
progressMessage = $("#message");
if (numValid == 0) {
progress.attr("value", "0");
progressMessage.text("Please Enter Student ID.");
}
if (numValid == 1) {
progress.attr("value", "10");
progressMessage.text("Please Enter the First Name.");
}
if (numValid == 2) {
progress.attr("value", "20");
progressMessage.text("Please Enter the Last Name.");
}
if (numValid == 3) {
progress.attr("value", "30");
progressMessage.text("Please Enter Your E-mail");
}
if (numValid == 4) {
progress.attr("value", "40");
progressMessage.text("Please Enter a Password.");
}
if (numValid == 5) {
progress.attr("value", "50");
progressMessage.text("Please Re-Enter a Password.");
}
if (numValid == 6) {
progress.attr("value", "60");
progressMessage.text("Please Enter A Street Address.");
}
if (numValid == 7) {
progress.attr("value", "70");
progressMessage.text("Please Enter a City.");
}
if (numValid == 8) {
progress.attr("value", "80");
progressMessage.text("Please Enter a ZipCode.");
}
if (numValid == 9) {
progress.attr("value", "100");
progressMessage.text("Please Pick a State and Submit the Form.");
}
});
答案 0 :(得分:1)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){ // do not forget to add this too
$("#form input").keyup(function() {
var numValid = 0;
$("#form input[required]").each(function() {
if (this.validity.valid) {
numValid++;
}
});
.
.
.
.
.
.
});
}); // and the closing braces
</script>
PS:请注意两个不同的<script>
标签。他们需要分开。另外,请不要忘记将keyup
函数包含在$(function(){});