【发布时间】:2011-01-16 13:54:26
【问题描述】:
我正在尝试为我的网站制作内容滑块。我有多个 HTML 文件,这些文件的结构是这样的:
<div id="title"><h2>Title of the Slide</h2></div>
<div id="image"><a href="http://mylink.com"><img src="image.jpg" width="600" height="300" alt="image"</a></div>
<div id="content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</div>
我一直在尝试使用以下脚本获取内容(但没有成功):
<?php
function render($position="") {
ob_start();
foreach(glob("/slides/*.html") as $fileName) {
$fname = basename( $fileName );
$curArr = file($fname);
$slides[$fname ]['title'] = $curArr[0];
$slides[$fname ]['image'] = $curArr[1];
$slides[$fname ]['content'] = $curArr[2];
foreach($slides as $key => $value){
?>
<div id="slide-title">
<?php echo $value['title'] ?>
</div>
<div id="slide-content">
<?php echo $value['content'] ?>
</div>
<div id="slide-image">
<?php echo $value['image'] ?>
</div>
<?php
}}
?>
<?php
return ob_get_clean();
}
但后来我知道了一个 jQuery 函数....(再次没有成功)
jQuery.noConflict();
(function($){
$(document).ready(function () {
$('#slide-title').load('slides/slide1.html #title');
$('#slide-content').load('slides/slide1.html #content');
$('#slide-image').load('slides/slide1.html #image');
});
})(jQuery);
现在我的问题是.....
我是否使用了正确的语法。
如何使用 jQuery 从多个文件中获取内容。
请注意:我的编程知识几乎是“0”。我刚刚开始学习它。
【问题讨论】: