PHP循环从循环图像调用属性

时间:2012-08-01 06:37:41

标签: php jquery

我创建了一个生成五个图像的while循环。然后,我将图像设计为拖动到网页的可放置部分。然后,我希望网页输出放置图像的位置。我唯一的问题是我希望代码也能从我从中获取图像的src中回显出来。出于某种原因,每当我点击任何图像并拖动它们时,页面只会回显第一个图像的src,而while循环则会循环播放。

<script type="text/javascript">

$(".droppable").droppable();

</script>

<?php

$num_dresses = dress_count ();

$i = 0;

while ($i < 5)

{   

$rand_id = rand(1, $num_dresses);

$new_file_name = html_entity_decode($dress_feed_data['file_name']); 

if (file_exists('fashion_images/' . $new_file_name))

{

?>

<script type="text/javascript" >

$(document).ready(function(){

$(function() 

  {

$(".ui-widget-content").draggable(

  {

stop: function(event,ui)
{
    var Stoppos = $(this).position();

    var className = $("img").attr("src");

    $(".location").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top + 

    className);

}});});});

</script>

<div class="ui-widget-content">

<img src="fashion_images/<?php echo $new_file_name;?> " width="70" height="70"/>

</div>

<?php

} 

$i++;   

}

?>

<div class="droppable"></div>

<div class="location"></div>  

1 个答案:

答案 0 :(得分:1)

杰森,

尝试:

$(".ui-widget-content img").draggable({
    stop: function(event, ui) {
        var Stoppos = $(this).position();
        var className = $(this).attr("src");
        $(".location").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top + className);
    }
});