2011-12-20 65 views
0

我創建了一個無限旋轉木馬。我想某些文本被選中的圖像時,可以顯示,但我不斷收到以下錯誤信息:不能調用方法未定義「分裂」用下面的腳本無法調用未定義的方法'拆分'

<script type="text/javascript"> 
jQuery(document).ready(function() { 
    jQuery('.set1').each(function() { 
    jQuery(this).before('<span>Some Text put here with Javascript... </span>'); 
}); 
}); 
</script> 

<div class="image_carousel"> 
    <div id="foo1"> 
<div class="set1"><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/vision-db-1.png" alt="Photography | Chad Pickard and Paul McLean" width="679" height="450" /></div><div class="set1"><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/vision-db-2.png" alt="Photography | Chad Pickard and Paul McLean" width="679" height="450" /></div><div class="set1"><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/vision-db-3.png" alt="Photography | Chad Pickard and Paul McLean" width="692" height="450" /></div><div class="set1"><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/vision-7.png" alt="Photography | Chad Pickard and Paul McLean" width="339" height="450" /></div><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/vision-8.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="338" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/vision-db-4.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="691" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/vision-11.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="339" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/vision-12.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="339" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/smug-1.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="710" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/smug-2.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="710" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/smug-3.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="710" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/smug-4.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="710" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/smug-5.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="710" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/volt-4.png" class="set2" alt="Photography | Rory DCS" width="675" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/volt-1.png" class="set2" alt="Photography | Rory DCS" width="675" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/volt-7.png" class="set2" alt="Photography | Rory DCS" width="675" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/volt-9.png" class="set2" alt="Photography | Rory DCS" width="675" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/volt-3.png" alt="Photography | Rory DCS" width="675" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/volt-11.png" class="set2" alt="Photography | Rory DCS" width="675" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/hay-5.png" class="set3" alt="Photography | Alex Sainsbury" width="312" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/hay-4.png" class="set3" alt="Photography | Alex Sainsbury" width="300" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/hay-2.png" class="set3" alt="Photography | Alex Sainsbury" width="279" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/hay-3.png" class="set3" alt="Photography | Alex Sainsbury" width="292" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/hay-1.png" class="set3" alt="Photography | Alex Sainsbury" width="308" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/gana-1.png" class="set4" alt="Photography | Robert Charbonnet" width="675" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/gana-2.png" class="set4" alt="Photography | Robert Charbonnet" width="300" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/gana-3.png" class="set4" alt="Photography | Robert Charbonnet" width="300" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/gana-4.png" class="set4" alt="Photography | Robert Charbonnet" width="300" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/Peregrine-Shot_03-4.png" alt="Photography | David Goldman" width="675" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/Peregrine-Shot_09-84.png" alt="Photography | David Goldman" width="300" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/Peregrine-Shot_10-192.png" alt="Photography | David Goldman" width="300" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/Peregrine-Shot_16-48.png" alt="Photography | David Goldman" width="675" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/Peregrine-Shot_17-131.png" alt="Photography | David Goldman" width="300" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/ss2011-shot05-173.png" alt="Photography | David Goldman" width="300" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/ss2011-shot06-72-1.png" alt="Photography | David Goldman" width="300" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-db-1.png" alt="Photography | Chad Pickard and Paul McLean" width="672" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-3.png" alt="Photography | Chad Pickard and Paul McLean" width="343" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-4.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="342" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-db-2.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="671" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-7.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="298" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-8.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="299" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-db-3.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="694" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-db-4.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="685" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-13.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="341" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-14.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="343" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/09/vc-15.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="342" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/lurve-5.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="301" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/lurve-2.png" class="set1" alt="Photography | Chad Pickard and Paul McLean" width="673" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/lurve-3.png" class="set1"alt="Photography | Chad Pickard and Paul McLean" width="301" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/vampire-weekend.png" class="set2" alt="Photography | Alan Clarke" width="660" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/grizzle-bear.png" class="set2" alt="Photography | Alan Clarke" width="660" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/tg-5.png" class="set3" alt="Photography | Harley Weir" width="588" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/tg-11.png" class="set3" alt="Photography | Harley Weir" width="343" height="450" /><img src="http://www.dwmu.co.uk/wp-content/uploads/2011/07/tg-12.png" class="set3" alt="Photography | Harley Weir" width="341" height="450" /> 
    </div> 
    <div class="clearfix"></div> 
    <a class="prev" id="foo1_prev" href="#"><span>prev</span></a> 
    <a class="next" id="foo1_next" href="#"><span>next</span></a> 
    <div class="logbox" id="foo1_log"><p>Click the previous- or next-button</p></div> 
</div> 

轉盤似乎紡輪,而不是顯示正確的文本

<script type="text/javascript" src="/wp-content/themes/child/script/jquery.jcarousel.min.js"></script> 
<script type="text/javascript" src="/wp-content/themes/child/script/carouFredSel.js"></script> 

<script type="text/javascript"> 
jQuery(document).ready(function() { 
    var imgLength = jQuery('ul#fredsel img').length; 
    jQuery('#totalImg').html(imgLength); 
    jQuery('#imgCount').html(1); 

    // Using custom configuration 
jQuery("#foo1").carouFredSel({ 
    items: 1, 
    align: false, 
    auto : false, 
    width: 1500, 
    onCreate: function(items) { 
     var txt = ""; 
     items.each(function() { txt += "<li>" + jQuery(this).attr("alt").split("/").pop() + "</li>"; }); 
     jQuery("#foo1_log").html("<p>Carousel created showing images:</p><ul>" + txt + "</ul>"); 
    }, 
    scroll : { 
    items   : 1, 
    duration  : 1000, 
    pauseDuration : 2000, 
     onAfter : function(oldItems, newItems) { 
      var txt = ""; 
      newItems.each(function() { txt += "<li>" + jQuery(this).attr("alt").split("/").pop() + "</li>"; }); 
      jQuery("#foo1_log").html("<p>Now showing images:</p><ul>" + txt + "</ul>"); 
     } 
    }, 
    prev : { 
     button : "#foo1_prev", 
     onBefore: function() { 
      jQuery("#foo1_log").html("<p>Started scrolling to the <strong>left</strong>.</p>"); 
     } 
    }, 
    next : { 
     button : "#foo1_next", 
     onBefore: function() { 
      jQuery("#foo1_log").html("<p>Started scrolling to the <strong>right</strong>.</p>"); 
     } 
    } 
}); 
}); 
</script> 
</head> 

任何想法?

回答

0

看起來您正嘗試加載的一個或多個圖像沒有alt屬性。試試這個:

onAfter : function(oldItems, newItems) { 
    var txt = ""; 
    newItems.each(function() { 
     var alt = jQuery(this).attr("alt") || ""; 
     txt += "<li>" + alt.split("/").pop() + "</li>"; 
    }); 
    jQuery("#foo1_log").html("<p>Now showing images:</p><ul>" + txt + "</ul>"); 
} 
0

然後jQuery的(本).attr( 「ALT」)是不是字符串或空

相關問題