English 中文(简体)
http://www.un.org
原标题:how to dynamic add <div> on html and write php inside html

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.

www.un.org/Depts/DGACM/index_french.htm

<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>

我是新手,请帮助我,我对此表示赞赏。

问题回答

是否将PHP与jquery混为一谈?

你们从PHP中可以直接写出html代码(I recomend a model 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>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签