【发布时间】:2011-11-21 23:25:47
【问题描述】:
我在一个页面上有多个对话框并将它们链接到 PHP 生成的 ID 时遇到了一些问题。我希望多个图像链接到包含内容的对话框......这是我的代码:
PHP:
<div id="children">
<?php
$children = array_values(get_pages(array('child_of' => $post->ID)));
foreach( $children as $ch => $child ){
echo '<div id="dialog-'.$child->ID.'" title="Basic dialog">';
echo $child->post_content;
echo '</div>';
}
foreach( $children as $ch => $child ){
$attachments = get_posts(array('numberposts'=> 1, 'post_parent' => $child->ID, 'post_type' => 'attachment', 'order' => 'DESC', 'orderby' => 'post_date'));
//print_r($attachments);
foreach( $attachments as $a => $attachment ){
echo '<a href="#opener-'.$child->ID.'" id="opener-'.$child->ID.'" >';
echo '<img class="attachment-thumb" src="'.$attachment->guid.'" width="150" height="150" />';
echo '</a> ';
}
}
//print_r($children)
?>
现在我意识到我的 jQuery 使用 1、2、3 而不是实际的 PHP ID 生成每个 id,但我不知道如何设置它,因此 jQuery 将链接到正确的对话框和开启程序。我需要使用 Ajax 吗?
jQuery:
<script>
$(function() {
var options = {
autoOpen: false,
width: 'auto',
modal: true
};
var num = 1;
$("#children").each(function() {
var dlg = $('#dialog-' + num).dialog(options);
$('#opener-' + num).click(function() {
dlg.dialog("open");
return false;
});
num = num + 1;
});
});
</script>
</div>
【问题讨论】:
标签: php jquery ajax jquery-ui jquery-ui-dialog