Javascript 如何在jQuery中重复函数?
我尝试在这个函数中使用无限循环,但是当我设置Javascript 如何在jQuery中重复函数?,javascript,html,jquery,Javascript,Html,Jquery,我尝试在这个函数中使用无限循环,但是当我设置setInterval时,函数不会重复。问题是当用户发送表单时,时间间隔过后。该函数保留在发送的消息上,不会从头开始。请看我的 Javascript: $(function(){ function show_fb() { $("#feedback_box").show("slow"); } function hideAll() { $("#feedback_box").hide("slow"); } $
setInterval
时,函数不会重复。问题是当用户发送表单时,时间间隔过后。该函数保留在发送的消息上,不会从头开始。请看我的
Javascript:
$(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
});
</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>
$(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
});
HTML:
$(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
});
</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>
$(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
});
给我们一些反馈:)X
您可以在jQuery中重复如下函数:
Javascript:
$(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
});
</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>
$(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中重复函数
这是您的答案。请不要发布带有可疑文件的Mediafire链接。使用jsBin或jsFiddle。好的,下一个问题我将使用jsBin谢谢您的信息。@BluemoonPro您不必等待下一个问题。使用演示替换此链接中的mediafire链接。此处显示其:
function repeat(){setTimeout(function(){repeat();},1);}repeat()代码>问题是你检查了脚本,你可以看到该功能正在发送一条消息,然后该功能重复它的操作,但从一开始就没有。除非引起用户的发送部分可以重新发送消息。