我创建了一个简单的 while 循环,可以生成文件夹中的随机图像。我希望能够将这些图像拖到我网页上的任何位置。我使用了 jQuery 的可拖动功能,但它不起作用。我的问题是这是否有效?这是简化的代码。
<script>
$(document).ready(function(){
$(function()
{
$("#draggable").draggable();
});
});
</script>
<?php
$num_dresses = dress_count ();
$i = 0;
while ($i < 5)
{
$rand_id = rand(1, $num_dresses);
$dress_feed_data = clothing_data($rand_id, 'file_name');
$new_file_name = html_entity_decode($dress_feed_data['file_name']);
if (file_exists('fashion_images/' . $new_file_name))
{
?>
<div id="draggable" class="ui-widget-content">
<img src=" fashion_images/<?php echo $new_file_name;?> " width="70" height="70"/>
</div>
<?php }
$i++;
}
?>
这是被视为页面源的代码。我删除了与问题无关的任何内容。
<?xml version="1.0"?>
<html>
<head>
<script>
$(document).ready(function(){
$(function()
{
$(".ui-widget-content").draggable();
});
});
</script>
<style>
#draggable { width: 50px; height: 50px; padding: 0.5em; }
</style>
</head>
<body>
<div class="ui-widget-content">
<img src=" fashion_images/blouse_belk's_0 " width="70" height="70"/>
</div>
<div class="ui-widget-content">
<img src=" fashion_images/red|nail|polish_opi_0 " width="70" height="70"/>
</div>
<div class="ui-widget-content">
<img src=" fashion_images/brown|pants_community|store_0 " width="70" height="70"/>
</div>
<div class="ui-widget-content">
<img src=" fashion_images/jeans_larry_0 " width="70" height="70"/>
</div>
<div class="ui-widget-content">
<img src=" fashion_images/pepsi|tshirt_target_1 " width="70" height="70"/>
</div>
</body>
</html>