0

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

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

1 回答 1

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);
    }
});
于 2012-08-01T07:52:01.020 回答