两个不同的Jquery Javascript代码不能在一个页面上工作

时间:2013-12-25 15:20:26

标签: javascript jquery

我在一个页面上有两个代码,第一个用于存储下拉菜单的最后一个状态,第二个用于发布数据。但这些不是在一页上工作。但是,当我在单个页面上尝试这些代码时,它工作正常。我是新人。提前致谢。

CODE:

$(document).ready(function(){

    var cookie = $.cookie("panelState"),
    expanded = cookie ? cookie.split("|").getUnique() : [],
    cookieExpires = 7; // cookie expires in 7 days, or set this as a date object to specify a date

    // show cookie content


    // Remember content that was expanded
    $.each( expanded, function(){
        $('#' + this).show();
    })

    $('li.primary').click(function(){
        $(this).toggleClass("open");
        $(this).next().slideToggle('300', function(){
            updateCookie(this);
        });
    })

    // Update the Cookie
    function updateCookie(el){
        var indx = el.id;
        var tmp = expanded.getUnique();
        if ($(el).is(':hidden')) {
            // remove element id from the list
            tmp.splice( tmp.indexOf(el.id) , 1);
        } else {
            // add index of widget to expanded list
            tmp.push(el.id);
        }
        expanded = tmp.getUnique();
        $.cookie("panelState", expanded.join('|'), { expires: cookieExpires } );


    }
});

// Return a unique array.
Array.prototype.getUnique = function(sort){
    var u = {}, a = [], i, l = this.length;
    for(i = 0; i < l; ++i){
        if(this[i] in u) { continue; }
        a.push(this[i]);
        u[this[i]] = 1;
    }
    return (sort) ? a.sort() : a;
}








    <script type="text/javascript">

    function loading_show(){
    $('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast');
}
function loading_hide(){
    $('#loading').fadeOut('fast');
}                
function loadData(page,qu,name){
    loading_show();                    
    $.ajax
    ({
        type: "POST",
        url: "urlbodies/editmembercomloaddata.php",
        data: "page="+page+"&qu="+qu+"&name="+name,
        success: function(msg)
        {
            $("#container").ajaxComplete(function(event, request, settings)
            {
                loading_hide();
                $("#container").html(msg);
            });
        }
    });
}




$('#pressbutton').live('click',function(){
    var qu = $('#commiteename').val();
    var name = $('#txtBox').val();
    loadData(1,qu,name);


}); 




loadData(1,"All","");  // For first time page load default results
$('#container .pagination li.active').live('click',function(){
    var page = $(this).attr('p');
    var qu = $('#commiteename').val();
    var name = $('#txtBox').val();
    loadData(page,qu,name);


});           
$('#go_btn').live('click',function(){
    var page = parseInt($('.goto').val());
    var no_of_pages = parseInt($('.total').attr('a'));
    if(page != 0 && page <= no_of_pages){
        var qu = $('#commiteename').val();
        var name = $('#txtBox').val();
        loadData(page,qu,name);
    }else{
        alert('Enter a PAGE between 1 and '+no_of_pages);
        $('.goto').val("").focus();
        return false;
    }

});

0 个答案:

没有答案