douchuo9476 2012-05-15 16:30
浏览 77

如何在html上动态添加<div>并在html中编写php

I want to use php to get Image file information in folder,and dynamic add image in div then add into web page,below is my code,but it does not work, please help me.

index.html

<div class="scrollContainer">   
  <?php
    var $i = 1;
    var $panel_id = "panel_";
    var $imgUrl = "./Img/";
    var $file=NULL;

    var $dir = opendir("Img");
    while( ($file = readdir($dir)) !== false ){
      $panel_id = $panel_id.$i;
      $imgUrl = $imgUrl.$file;
      echo "$('.scrollContainer').html("
          ."$('<div/>')"
          .".addClass('panel')"
          .".id(".$panel_id.")"
          .".append("
          ."$('<div/>')"
          .".addClass('inside')"
          .".append("
          ."$('<img/>')"
          .".attr('src',".$imgUrl.")"
          .")"
          .".append("
          ."$('<p/>')"
          .".text(".$file.")"
          .")"
          .")"
          .");";

      $panel_id = "panel_";
      $imgUrl = "./Img/";
      $i = $i + 1;
    } // while

    closedir( $dir );
  ?> 
<div>

I am new hand, please help me , I appreciate it.

  • 写回答

1条回答 默认 最新

  • dtmu88600 2012-05-15 16:43
    关注

    You are combinate PHP with jquery create objects method???

    You from PHP can write html code directly (I recomend a template sistaxis):

      <?php
        var $i = 1;
        var $panel_id = "panel_";
        var $imgUrl = "./Img/";
        var $file=NULL;
    
        var $dir = opendir("Img");
    
        ?>
    
    
    
        <div class="scrollContainer">
    
        <?php while( ($file = readdir($dir)) !== false ) : ?>
    
             <div src="panel" id="<?= $panel_id.$i ?>">
                  <div class="inside">
                      <img src="img/<?= $imgUrl.$file ?>" />
                      <p><?= htmlentities($file) ?></p>
                  </div>
             </div>  
          <?php $i++; ?>
        <?php endwhile; ?>
    
      <?php
      closedir( $dir );
      ?> 
      </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀