我创建了一个infinte轮播。我希望在选择图像时显示某些文本但我不断收到以下错误消息:无法使用以下脚本调用undefined方法'split'
<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 :(得分: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>");
}
答案 1 :(得分:0)
然后jQuery(this).attr(“alt”)不是字符串或空