Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
值匹配时中断jQuery循环_Jquery - Fatal编程技术网

值匹配时中断jQuery循环

值匹配时中断jQuery循环,jquery,Jquery,我将当前日期和时间与我拥有的日期和时间列表进行比较。在代码的最后,我将比较getDates是否大于输出。我想在它为真时停止循环,并使用匹配的值(为了停止循环,我使用returnfalse)。请问我怎么做?我做了一张便条,上面写着“匹配值在这里”,我想这就是我需要插入内容的地方 // Get current date, format it var d = new Date(); var month = d.getMonth()+1; var day = d.getDate(); var

我将当前日期和时间与我拥有的日期和时间列表进行比较。在代码的最后,我将比较getDates是否大于输出。我想在它为真时停止循环,并使用匹配的值(为了停止循环,我使用returnfalse)。请问我怎么做?我做了一张便条,上面写着“匹配值在这里”,我想这就是我需要插入内容的地方

    // Get current date, format it
var d = new Date();

var month = d.getMonth()+1;
var day = d.getDate();
var hour = d.getHours();
var minute = d.getMinutes();

var output = d.getFullYear() + '-' +
((''+month).length<2 ? '0' : '') + month + '-' +
((''+day).length<2 ? '0' : '') + day + ' ' +
((''+hour).length<2 ? '0' :'') + hour + ':' +
((''+minute).length<2 ? '0' :'') + minute
alert(output)

// Get all dates and time found in the table on this page
$('td:first-child').each(function() {
    var getDates = $(this).text();


// Check if dates in table expired. If expired skip and display upcoming one
// if getDates is bigger than output then stop looping and use it

    if ( getDates > output) {
        alert('true')
        return false;
        $('#defaultCountdown').countdown({until: new Date(MATCHED VALUE GOES HERE)});
    }
//获取当前日期,格式化它
var d=新日期();
变量月份=d.getMonth()+1;
var day=d.getDate();
var hour=d.getHours();
var minute=d.getMinutes();
变量输出=d.getFullYear()+'-'+

((''+月)。长度在设置
倒计时之前返回

试一试


使函数返回false

$('td:first-child').each(function() {
    var getDates = $(this).text();


// Check if dates in table expired. If expired skip and display upcoming one
// if getDates is bigger than output then stop looping and use it

    if ( getDates > output) {
        alert('true')
        $('#defaultCountdown').countdown({until: new Date(MATCHED VALUE GOES HERE)});
        return false;
    }
}
从文档中:

我们可以通过使回调函数>return false在特定迭代中中断$.each()循环。返回non false与for循环中的continue语句相同;它>将立即跳到下一个迭代

可能重复的
$('td:first-child').each(function() {
    var getDates = $(this).text();


// Check if dates in table expired. If expired skip and display upcoming one
// if getDates is bigger than output then stop looping and use it

    if ( getDates > output) {
        alert('true')
        $('#defaultCountdown').countdown({until: new Date(MATCHED VALUE GOES HERE)});
        return false;
    }
}