저는 JavaScript를 처음 사용합니다. ِ 오류없이 양식을 제출할 때 다음 스크립트에 로딩 이미지 (gif)를 추가하기 만하면됩니다.
인터넷에서 사용할 수있는 스크립트 (jQuery를 사용한 Facebook과 유사한 등록 양식)와 함께 코드를 사용합니다.
도와주세요.
$(document).ready(function () {
$('#regForm').submit(function (e) {
register();
e.preventDefault();
});
});
function register() {
hideshow('loading', 1);
error(0);
$.ajax({
type: "POST",
url: "submit.php",
data: $('#regForm').serialize(),
dataType: "json",
success: function (msg) {
if (parseInt(msg.status) == 1) {
window.location = msg.txt;
} else if (parseInt(msg.status) == 0) {
error(1, msg.txt);
}
hideshow('loading', 0);
}
});
}
function hideshow(el, act) {
if (act) $('#' + el).css('visibility', 'visible');
else $('#' + el).css('visibility', 'hidden');
}
function error(act, txt) {
hideshow('error', act);
if (txt) $('#error').html(txt);
}
2 개의 요소가 필요합니다.
<img src="loading.gif" id="loading" style="visibility:hidden">
(hideshow ( 'loading', 1)로 표시되고 서버가 응답하면 다시 숨 깁니다. 또 다른
<img src="error.gif" id="error" style="visibility:hidden">
오류. 물론 loading.gif 및 error.gif는 유효한 이미지 파일이 될 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다