0
<div id = "newdiv">
</div>    
<?php 
    $qry = "SELECT * from contact Where CustomerID='57'";
    $result = mysql_query($qry);
    while ($row = mysql_fetch_array($result)) {         
?>
<script type="text/javascript" language="javascript">
    function createDiv() {
        $('#newdiv').append('<div id="div"'+i+'" class="ex" style="text-align: left;"><div id="div"'+i+'" class= "square"><table border="0" class = "table" ><tr><td width="51">Name:</td><td width="141"><input type="text" size="10" class = "name"></td></tr><tr><td>Title:</td><td><input type="text" size="10" class = "title"></td></tr><tr><td>Contact:</td><td><input type="text" size="10"  class = "contact"></td></tr></table></div><img class="myimage" ondblclick="changeimage(this)" border="0"src="images/white_contact.png" width="60" /></div>');
        $( ".ex" ).draggable({containment:'parent',cursor:'pointer',opacity:0.6});
        $( ".ex" ).droppable();
    }
    createDiv(); // will execute when it loads this line
</script>
<?php
    }
?>

我想使用 PHP 的 while 循环来检查它找到的每个联系人的 Customer 57 的联系人数量,它应该生成一个 DIV,依此类推,它们应该相互附加

我的代码只是不工作,为什么会这样?我正在使用 while 循环调用 CreateDiv() 函数

4

3 回答 3

0
<script type="text/javascript" language="javascript">
    function createDiv() {
           $('#newdiv').append('<div id="div"'+i+'" class="ex" style="text-align:    left;">
                <div id="div"'+i+'" class= "square"><table border="0" class = "table" ><tr>
                <td width="51">Name:</td><td width="141"><input type="text" size="10" class = "name">
                </td></tr><tr><td>Title:</td><td><input type="text" size="10" class = "title">
                </td></tr><tr><td>Contact:</td><td><input type="text" size="10"  class = "contact">
               </td></tr></table></div><img class="myimage"    ondblclick="changeimage(this)" border="0"src="images/white_contact.png" width="60" />    </div>');

            $( ".ex" ).draggable({containment:'parent',cursor:'pointer',opacity:0.6});
            $( ".ex" ).droppable();
        }

   </script>
<div id = "newdiv">

</div>    

$qry = "SELECT * from contact Where CustomerID='57'";
$result = mysql_query($qry);
while ($row = mysql_fetch_array($result)) 
{
?>

   <script type="text/javascript" language="javascript">
      createDiv(); // will execute when it loads this line
   </script>

<?php
}
?>
于 2013-06-04T09:40:01.103 回答
0

$("body").append('<div id="foo">blabla</div>')

或者,如果您想替换现有 div 的内容。

$('#newdiv').html('..whatever..')

于 2013-06-04T09:34:32.323 回答
0

PHP

<?php 
    $qry = "SELECT * from contact Where CustomerID='57'";
    $result = mysql_query($qry); 
    $count = mysql_num_rows($result);
    while ($row = mysql_fetch_array($result)) {  

    }       
?>

HTML

<html>
<head></head>
<body>
  <div id="newdiv"></div>
  <input type="hidden" name="count" value="<?=$count?>"/>
</body> 
</html>

查询

<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
   $(function() {
     createDiv();

      function createDiv(){
        var count = $('[name="count"]').val();
        for (var i=1;i<=count;i++) {
          $('#newdiv').append('<div id="div'+ i +'" class="ex" style="text-align: left;"><div id="div'+ i +'" class= "square"><table border="0" class = "table" ><tr><td width="51">Name:</td><td width="141"><input type="text" size="10" class = "name"></td></tr><tr><td>Title:</td><td><input type="text" size="10" class = "title"></td></tr><tr><td>Contact:</td><td><input type="text" size="10"  class = "contact"></td></tr></table></div><img class="myimage" ondblclick="changeimage(this)" border="0"src="images/white_contact.png" width="60" /></div>');
        }
      }


    });
</script>
于 2013-06-04T09:53:15.730 回答