jquery变量if语句

时间:2014-08-07 18:51:29

标签: javascript php jquery

我正在尝试将目标ID形式的php变量从复选框传递到我的javascript中,如果页面加载了更多结果,则会触发。

通过使用console.log并找出如何设置变量,我可以拉出目标IDS。

我在实现if else语句时遇到了麻烦。我已经使用了.val()和.length(),但它似乎不起作用。

我基本上希望它能像if(destination.length() < 1 ) {execute the jquery}那样工作,如果目标值不为空或为null,则不执行任何操作......

这是我的代码!感谢您抽出宝贵时间提供帮助。

Query(document).ready(function() {
    var is_loaded = true;
    var nextPage = 2 ;
    var destination = $("input[name='destinations[]']:checked").val() ;
    console.log(destination);
    jQuery(window).scroll(function() {
        if(destination.length() < 1) {
            if(jQuery(window).scrollTop() == jQuery(document).height() - jQuery(window).height()) {
                jQuery('div#loadMore').show();
                if(is_loaded){
                    is_loaded = false;
                    jQuery.ajax({
                        type: 'GET',
                        url: 'http://www.pgtpackages.com/api_courselist.php?offset='+ nextPage +'&format=html',
                        success: function(html) {
                            console.log(html);
                            is_loaded = true;
                            nextPage++;
                            if(html){
                                jQuery("#infiscroll").append(html);
                                jQuery('div#loadMore').hide();
                            }else{
                                jQuery('div#loadMore').replaceWith("<center><h1  style='color:red'>End of Content !!!!!!!</h1></center>");
                            }
                        }
                    });

                }
            }
        }//DESTINATION.val
    });
});
});

1 个答案:

答案 0 :(得分:0)

更新

var destination = $("input[name='destinations[]']:checked").val()

var destination = $("input[name='destinations[]']:checked").length;

现在destination会为您提供所选复选框的确切数量,您可以if使用destination

这样的东西
if(destination<1){//run code}