0

我有点坚持如何根据带有 Jquery 的可放置对象的 ID 更改我的图像 src 的一部分。

我从网上尝试了这个和其他一些想法,但不幸的是没有奏效。如果我必须这么说,这很棘手。

ui.draggable['<img src= "images/kitchen/.img src" width="800" height="600"/>'].id

目前我只能图像一次。

我想我应该做某种功能来执行 img src。

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Droppable - Revert draggable position</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<style>
#draggable, #draggable1 { width: 100px; height: 100px; padding: 0; float: left; margin: 10px 10px 10px 0; }
#droppable { width: 800px; height: 600px; padding: 0; float: left; margin: 10px; }
</style>
<script>
$(function() {
$( "#draggable" ).draggable({ revert: "valid" });
$( "#draggable1" ).draggable({ revert: "valid" });
$( "#droppable" ).droppable({
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
drop: function( event, ui ) {
$( this )
    .addClass( "ui-state-highlight" )
    .find( "div" )
    .html('<img src= "http://blakeloizides.co.za/sm/images/preview-images/kitchen/medium-cream-kitchen-preview.jpg" width="800" height="600"/>' + "Dropped! " + ui.draggable[0].id);

}
});
});
</script>
</head>
<body>
<div id="draggable" class="ui-widget-content">
<img src="http://blakeloizides.co.za/sm/images/gallery/img12.png" width="100" height="100">
</div>

<div id="draggable1" class="ui-widget-content">
<img src="http://blakeloizides.co.za/sm/images/gallery/img1.png" width="100" height="100">
</div>

<div id="droppable" class="ui-widget-header">
<div><img src="images/kitchen/kitchen-preview-cad.jpg" width="800" height="600"></div>
</div>
</body>
</html>
4

1 回答 1

1

这应该工作

            <!doctype html>
            <html lang="en">
            <head>
            <meta charset="utf-8" />
            <title>jQuery UI Droppable - Revert draggable position</title>
            <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
            <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
            <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
            <style>
            #draggable, #draggable1 { width: 100px; height: 100px; padding: 0; float: left; margin: 10px 10px 10px 0; }
            #droppable { width: 800px; height: 600px; padding: 0; float: left; margin: 10px; }
            </style>
            <script>
            $(function() {
            $( "#draggable" ).draggable({ revert: "valid" });
            $( "#draggable1" ).draggable({ revert: "valid" });
            $( "#droppable" ).droppable({
            activeClass: "ui-state-hover",
            hoverClass: "ui-state-active",
            drop: function( event, ui ) {
            var dragElemId = ui.draggable[0].id;
            var imgPath = $('#' + dragElemId).attr("des-image");
            $( this )
                .find( ".drop-image" ).removeAttr("src").attr("src",imgPath);
            }
            });
            });
            </script>
            </head>
            <body>
            <div id="draggable" class="ui-widget-content" des-image="http://blakeloizides.co.za/sm/images/preview-images/kitchen/medium-cream-kitchen-preview.jpg">
            <img src="http://blakeloizides.co.za/sm/images/gallery/img12.png"  width="100" height="100">
            </div>

            <div id="draggable1" class="ui-widget-content" des-image="http://blakeloizides.co.za/sm/images/gallery/img12.png">
            <img src="http://blakeloizides.co.za/sm/images/gallery/img1.png"  width="100" height="100">
            </div>

            <div id="droppable" class="ui-widget-header">
            <div><img class="drop-image" src="images/kitchen/kitchen-preview-cad.jpg" width="800" height="600"></div>
            </div>
            </body>
            </html>
于 2013-03-18T17:39:52.780 回答