2
我的第一篇文章。我目前正在學習,因爲我跟着這個項目一起工作,對我一無所知!添加Jquery之間的其他函數調用
下面你會找到該程序的代碼。基本上,我有jquery調用淡入淡出div。但是,在Jquery淡出並淡入另一個div之前,我想檢查表單驗證和用戶輸入。我的問題是,我如何在Jquery之間正確添加其他函數,就像我爲validateForm()所做的那樣。 & validatePostalCode(); ?
JQUERY
<script type="text/jquery>
$(document).ready(function() {
$("#welcome").fadeIn('fast');
$('#forward').click(function(e) {
$('#welcome').fadeOut('fast', function() {
$('#service').fadeIn('fast');
});
});
$('#previous-service').click(function(e) {
$('#service').fadeOut('fast', function() {
$('#welcome').fadeIn('fast');
});
});
$('#next-service').click(function(e) {
postalCode();
validatePostalCode(true);
$('#service').fadeOut('fast', function() {
$('#match').fadeIn('fast');
});
});
$('#previous-match').click(function(e) {
$('#match').fadeOut('fast', function() {
$('#service').fadeIn('fast');
});
});
$('#next-match').click(function(e) {
$('#match').fadeOut('fast', function() {
$('#information').fadeIn('fast');
});
});
$('#previous-information').click(function(e) {
$('#information').fadeOut('fast', function() {
$('#match').fadeIn('fast');
});
});
$('#next-information').click(function(e) {
validateForm();
$('#information').fadeOut('fast', function() {
$('#confirmation').fadeIn('fast');
});
});
JAVASCRIPT
<script type="text/javascript">
function validateForm() {
var x = document.forms["#information"]["#first_name"].value;
if (x == null || x == "") {
alert("First name must be filled out");
return false;
}
}
function validatePostalCode() {
var x = document.forms["#serviceForm"]["#postal"].value;
if (x == null || x == "") {
alert("Oops, the postal code must be filled out!");
return false;
}
}
</script>
<script type="text/javascript">
function postalCode() {
var text = document.getElementById('postal').value;
}
</script>
HTML
<form id="informationForm" action="" onsubmit="return validateForm()" method="">
<div class="form-group">
<label for="first_name">First Name</label>
<input type="text" class="form-control" id="first_name" autofocus required>
</div>
我會串聯所有的文件後,我一起全面檢討所有的功能。使我更容易發展!謝謝 :) – ColeGauthier