我很难让两个jquery脚本一个接一个地工作

Im having trouble making two jquery scripts work one after the other

本文关键字:一个 工作 脚本 两个 很难 jquery      更新时间:2023-09-26

第二个脚本在使用第一个脚本加载后不起作用

我正试图用这个加载它

$(document).ready(function() {

$('div.frame ul#main li a').click(function(){
        var toLoad = $(this).attr('href')+' #content';
        $('#content').hide('fast',loadContent);
        function loadContent() {
            $('#content').load(toLoad,'',showNewContent())
        }
        function showNewContent() {
            $('#content').show('normal',hideLoader());
        }
        function hideLoader() {
            $('#load').fadeOut('normal');
        }
        return false;
    });
});

一页加载后使用这个

$(document).ready(function(e) {

    var currentportfolio = $('div#slider ul li:first-child').addClass('show');
    var portfolio = $('div#slider ul li');  
    $('div#slider ul li').not(':first').hide();

    $('.prev, .next').click(function() {
    // Determine the direction, -1 is prev, 1 is next
    var dir = $(this).hasClass('prev') ? -1 : 1;
    // Get the li that is currently visible
    var current = $('div#slider ul li:visible');
    // Get the element that should be shown next according to direction
    var new_el = dir < 0 ? current.prev('li') : current.next('li');
    // If we've reached the end, select first/last depending on direction
    if(new_el.size() == 0) {
        new_el = $('div#slider ul li:'+(dir < 0 ? 'last' : 'first'));
    }
    // Hide them all..
    $('div#slider ul li').hide();
    // And show the new one
    new_el.show();
    // Prevent the link from actually redirecting the browser somewhere
    return false;
});
});

我是jQuery的新手。提前谢谢。

查看.load的文档。jQuery提供了一个"回调"函数作为.load函数的一部分。回调基本上是在.load完成后运行的。看起来你已经在用了。

http://api.jquery.com/load/

    function showNewContent() {
        $('#content').show('normal',hideLoader());
        additionalStuffToDoAfterLoad();
    }
    function additionalStuffToDoAfterLoad(){
         //all the stuff in section 2 goes here.
    }