1

看看这里: http ://test.neworgan.org/100/

向下滚动到社区部分。

我想要实现的是为新的组织者获取数据(例如:朋友的数量/捐赠的金额),以便在用户点击他们的缩略图时显示。现在,每个用户都有自己独特的数据存储在外部。

一旦用户单击缩略图,“inline1”就会与内容一起出现。

截至目前,无论我点击哪个用户的缩略图,我都只能从最后一个用户那里获取数据来显示。关于如何根据用户单击的缩略图更改内容,我只需要一些帮助。所以我想知道我是否可以在这里得到一些帮助?

这是重要的代码部分:

      <div class="top-fundraisers-wrapper">
     <div class="subsection top-fundraisers">

    <?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
        <?php foreach ($top_fundraisers as $index => $fundraiser): ?>
           <a title="" class="fancybox" href="#inline1">
        <div class="top-fundraiser">

<div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
              <img src="<?php
          if($fundraiser['member_pic_medium']) {
                  print htmlentities($fundraiser['member_pic_medium']);
          } else {
            print $template_dir . '/images/portrait_placeholder.png';
          }
              ?>"/>
            </div>
    </div>
    </a>
        <?php endforeach;?>
    <?php endif; ?>

  </div>
</div>
</div>

<div id="inline1">
    <div class="top-fundraiser-image2">
    <img src="<?php
          if($fundraiser['member_pic_large']) { print htmlentities($fundraiser['member_pic_large']);
          } else {
            print $template_dir . '/images/portrait_placeholder.png';
          }
            ?>"/>
            </div>

    <span class="member-name"><?php print htmlentities($fundraiser['member_name']); ?></span>
        <span class="friend-count"><?php print number_format($fundraiser['num_donors']) . (($fundraiser['num_donors'] == 1) ? ' Friend' : ' Friends'); ?></span>


        <span class="fundraisers-text"> Donated: </span><span class="fundraisers-gold"> $<?php print number_format($fundraiser['total_raised']); ?></span>

</div>
4

4 回答 4

0

为内容创建另一个循环

<?php if ($top_fundraisers && is_array($top_fundraisers)):
    $i = 1;
    foreach ($top_fundraisers as $index => $fundraiser): ?>
        <a title="" class="fancybox" href="#inline<?php echo $i; ?>">
        // ... content
    <?php $i++;
    endforeach;
endif; ?>

还有另一个循环

<?php if ($top_fundraisers && is_array($top_fundraisers)):
    $i = 1;
    foreach ($top_fundraisers as $index => $fundraiser): ?>
        <div id="inline<?php echo $i; ?>">
            // inline content here
        </div>
    <?php $i++;
    endforeach;
endif; ?>
于 2016-12-12T10:47:08.833 回答
0

希望您的 JavaScript 函数通过调用类来打开 fancybox 工作正常。因此,通过以下代码,您无需使用 Javascript 代码。

建筑锚标签:

<?php
if (!empty($top_fundraisers) && is_array($top_fundraisers)) {
    foreach ($top_fundraisers as $index => $fundraiser) {
        <a title="" class="fancybox" href="#inline<?php echo $fundraiser['id']; ?>">HTML Content Goes Here</a>
        <?php
    } //end of foreach
} // end of if condition
?>

构建弹出式 HTML DOM:

<?php
if (!empty($top_fundraisers) && is_array($top_fundraisers)) {
    foreach ($top_fundraisers as $index => $fundraiser) {
         <div id="inline<?php echo $fundraiser['id']; ?>">HTML Content Goes Here</div>
        <?php
    } //end of foreach
} // end of if condition
?>
于 2016-12-12T11:17:01.557 回答
0

最好的方法是使用 Ajax。像这样的东西

$("#button").click( function() {
$.ajax({
    url: 'file.php',
    method: 'post',
    data: { id: $(this).val() },
    error: function() {
        alert('error while requesting...');
    }, success: function(data) {
        alert( data ); /** received data - best to use son **/
    }
 });
 });

接下来解析 json var json = $.parseJSON(data); 或...使用 dataJson 选项。

Next 您的数据应该使用 class 或 id 插入到特定位置。

于 2016-12-12T10:41:49.230 回答
-1

您无法执行此操作,因为 PHP 在服务器端运行,而 JavaScript 在浏览器中运行。

要执行此操作,您可以使用AJAX来获取div用户所需的。

...或在客户端存储数据并#inline1根据单击的项目更改内容

于 2012-09-25T10:31:18.333 回答