이 함수 내에서 무한 루프를 사용해 보았지만, setInterval
을 설정하면 함수가 반복되지 않습니다. 문제는 사용자가 양식을 보내고 시간이 경과 한 후에 발생합니다. 이 기능은 보낸 메시지에 머무르며 처음부터 시작하지 않습니다. 내 JSBin을 참조하십시오.jQuery에서 어떻게 함수를 반복 할 수 있습니까?
자바 스크립트 :
$(function(){
function show_fb() {
$("#feedback_box").show("slow");
}
function hideAll() {
$("#feedback_box").hide("slow");
}
$("#feedback_box #close").click(function() { // When the X is pressed
$("#feedback_box").hide("slow"); // Hide the form
});
setInterval(show_fb,1000); // Show the form after 6 seconds , you can change 6000 to anything you like
$("#feedback_form").submit(function() { //When the form is submitted
$('#feedback_form #fb_title').css('background-color','#4444FF').text('Sending...').slideDown(900); //show "Sending" message
$.post("form_submit.php",{ mesaj:$('#mesaj').val(),rand:Math.random() } ,function(data) { //subimit the feedback via AJAX
$('#feed_subm').attr("disabled", "false"); //disable the "SEND" button
$('#feedback_form #fb_title').css('background-color','#C33').text('Thank You!').slideDown(900); //Shows a thank you message
setTimeout(hideAll,2000); // Hide the form after 2 seconds
});
});
return false; //Tells the code not to post the form physically
});
HTML :이 같은 jQuery를에 함수를 반복 할 수 있습니다
</head>
<body>
<div id="feedback_box">
<form id="feedback_form">
<span id="fb_title">Give us some feedback :)</span><span id="close">X</span>
<textarea id="mesaj"></textarea>
<input type="submit" value="Send" class="mysubm" id="feed_subm"/>
</form>
</div>
</body>
Mediafire 링크를 모호한 파일로 게시하지 마십시오. jsBin 또는 jsFiddle을 사용하십시오. – elclanrs
오케이, 다음은 JsBin을 이용해 주셔서 감사합니다. –
@BlueMoonMoonPro 다음 질문을 기다릴 필요가 없습니다. 이 중 하나의 미디어 파이어 링크를 데모로 교체하십시오. –