开发者

event.target doesn't work

开发者 https://www.devze.com 2022-12-28 20:25 出处:网络
I\'ve wrote some jquery code with some draggable elements and one droparea. Unfortunately my droparea can\'t make a difference between various object.

I've wrote some jquery code with some draggable elements and one droparea.

Unfortunately my droparea can't make a difference between various object.

Here's my code.

<script type="text/javascript">

    $(function() {

        $("#droparea").droppable({
            drop: function(event) {
                var $target = $(event.target);

                if($target.is("#flyer")) {
                    alert("adasd");
                 }
                   else if($target.is("#flyer2")) {
                    alert("adasd2");
                 }
            }
        });

    });
开发者_C百科

</script>

</head>
<body>
<div id="droparea"></div>

<div class="polaroid" id="flyer">
    <img src="images/muesliFlyer.png" alt="flyer" />
</div>

Without the if it works. But then I can't get the dropped object.

Any ideas why my target isn't recognized?

thanks a lot.


The way to get the dropped element is to have two parameters to your drop method (generally event and ui) and get the "draggable" property from the ui parameter.

    $("#droparea").droppable({
        drop: function(event, ui) {
            var $target = ui.draggable; //note: draggable is a jQuery object

            if($target.is("#flyer")) {
                alert("adasd");
            }
        }
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消