【问题标题】:jQuery UI Multiple Dialog & PHPjQuery UI 多对话框和 PHP
【发布时间】: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


    【解决方案1】:

    $("#children").each 只运行一次,用于一个“儿童” div。因此 num 在此函数中永远不会大于 1。您可能需要$("#children div").each,它将为“children”的所有 div 子级执行。

    (从技术上讲,num 变为 2(在 1 执行后)......但在 2 时永远不会被执行。)

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 2012-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多