0

我的第一个脚本提供给随机图像,如下所示

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<!-- include Cycle plugin -->
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>
<script type="text/javascript">
    var $t = jQuery.noConflict();
    $t(function () {
        $t('.slideshow').cycle({
            fx: 'fade' 
        });
    });
</script>

当我添加一些这样的图像时它会起作用

<div class="news_area_left">
     <div class="slideshow" style="position: relative; ">
        <img src="../../banner_image/nemo.jpg" width="154px" height="108px"/>
  <img src="../../banner_image/up.jpg" width="154px" height="108px" />

</div>
    </div> 

但是当我添加我的第二个脚本时,它会得到你可以看到的图像

<script type="text/javascript">

    $(function () {

        $.ajax({
            type: "get", url: "Home/Oku", data: {}, dataType: "json",
            success: function (data) {

                for (var i = 0; i < data.length; i++) {

                   var newFirmDiv= $(' <img src="../../banner_image/' + data[i] + '" width="154px" height="108px"/>');
                    $(".slideshow").append(newFirmDiv);

                }
            }
        });
    });

</script>

最后我尝试在我的“幻灯片 div”中使用我的动态图像,但效果不起作用

<div class="news_area_left">
     <div class="slideshow" style="position: relative; ">
       </div>
    </div>
4

1 回答 1

0

您需要$t('.slideshow').cycle在动态插入图像后运行。您还需要附加到“幻灯片”类而不是“firmShowCase”类。

请参阅我创建的这个 jsFiddle http://jsfiddle.net/davew9999/sgUeq/

HTML

<div class="news_area_left">
     <div class="slideshow" style="position: relative; ">
         <img src="http://activephilosophy.files.wordpress.com/2009/09/number1.jpg" width="154px" height="108px"/>
         <img src="http://www.clker.com/cliparts/h/Y/i/C/Y/W/red-rounded-square-with-number-2-md.png" width="154px" height="108px"/>
     </div>
</div>​

JavaScript

var $t = jQuery.noConflict();

var newFirmDiv = $t('<img src="http://www.mosamuse.com/wp-content/uploads/2012/05/number3.png" width="154px" height="108px"/>');
$t(".slideshow").append(newFirmDiv);

var anotherDiv = $t('<img src="http://2.bp.blogspot.com/-_A_8UYb0zIQ/Te5lpI9iZ3I/AAAAAAABgWk/sErDyHjEhPw/s1600/number-4.jpg" width="154px" height="108px"/>');
$t(".slideshow").append(anotherDiv);

$t(function() {
    $t('.slideshow').cycle({
        fx: 'fade'
    });
});
于 2012-08-05T20:11:50.187 回答