2013-01-06 11 views
0

이 함수 내에서 무한 루프를 사용해 보았지만, 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> 
+2

Mediafire 링크를 모호한 파일로 게시하지 마십시오. jsBin 또는 jsFiddle을 사용하십시오. – elclanrs

+0

오케이, 다음은 JsBin을 이용해 주셔서 감사합니다. –

+1

@BlueMoonMoonPro 다음 질문을 기다릴 필요가 없습니다. 이 중 하나의 미디어 파이어 링크를 데모로 교체하십시오. –

답변

0

:

자바 스크립트 :

$(document).ready(function() { 

    // First we will create the function that will be repeated 
    function repeat() { 

    setTimeout(function() { 

     // Enter your code that you want to repeat in here 

     repeat(); // This is where the function repeats 

    }, 1); // Where 1 is the delay (in milliseconds) 

    } 

    repeat(); // Here we are initially firing the function 

}); 

위의 예에서 함수가 계속 반복되어야하지만 질문이 인 이유를 알 수 없습니다. jQuery에서 함수를 반복 할 수 있습니까?

내가 생각하는 것 jQuery에서 어떻게 함수를 반복 할 수 있습니까?

그럼 답변을 드리겠습니다.

+0

문제는 스크립트를 확인하면 fuction이 메시지를 보낸다는 것을 알 수 있습니다. 그러면 fuction은 처음부터 다시 작업을 반복합니다. usaers를 일으키는 전송 부분이 메시지를 다시 보낼 수 없다면. –

관련 문제