问题
I came across a carousel from Twitter bootstrap here. http://twitter.github.com/bootstrap/javascript.html#carousel
It looks really good. But all the images / content in the example are hard-coded. How can I request the server for new content and show it in the carousel?
回答1:
The answer would have to be adjusted for each language, but assuming you're programing in PHP, it may look something like this:
If you have an array of images:
$images = ['path/to/image.jpg', 'path/to/image2.jpg', 'path/to/image3.jpg']
Then you'd loop through those images, and place each one in the appropriate HTML markup, like so:
<?php foreach ($images as $image) { ?>
<div class="item">
<img src="<?php echo $image ?>" />
</div>
<?php } ?>
来源:https://stackoverflow.com/questions/10232618/carousel-with-dynamic-content