我創建了一個簡單的while循環,用於生成我的文件夾中的隨機圖像。我希望能夠將這些圖像拖放到我的網頁上的任何位置。我用jQuery的可拖動函數,但它不起作用。我的問題是,這甚至工作?這裏是簡化的代碼。jQuery可拖動函數和while循環
<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>
感謝您的幫助和建議。我將選擇器更改爲.ui-widget-content,但它仍然不起作用。 – jason328 2012-07-24 04:25:45
@ jason328你可以從視圖源顯示代碼隱藏,實際上生成 – 2012-07-24 04:30:47
當然可以。添加到我的問題。 – jason328 2012-07-24 04:40:24