0

我仍在学习 jQuery,并且在使用eruciform 的 jquery-collision 插件文档)时遇到了最困难的时间。

我需要的只是获取我的可拖动对象在 mouseup 上重叠的 div 的名称,但它似乎只想将函数本身的代码作为文本返回。

这是一个jsFiddle。我究竟做错了什么?

标记:

<div id="mainDiv" class="mainDiv">
    <div class="topNav" id="topNav">
        <div class="dragElements">
            <div class="draggable" id="drag01">One</div>
            <div class="draggable" id="drag02">Two</div>
            <div class="draggable" id="drag03">Three</div>
            <div class="draggable" id="drag04">Four</div>
        </div>
        <div class="dropElements">
            <div class="venn" id="venn1">
                <p/>&nbsp;<p/>Blue:
            </div>
            <div class="venn" id="venn2">
            <p/>&nbsp;<p/>Orange:
            </div>
        </div>
    </div>
</div>

款式:

.dragElements{
    width: 100%;
    height: 170px;
}
.dropElements{
    width: 100%;
    height: 275px;
}
#venn1{
    width:275px;
    height:275px;
    background-color:#0066FF;
    position:absolute;
    float:left;
    left: 0px;
    text-align: center;
}
#venn2{
    width:275px;
    height:275px;
    background-color:#FC0;
    position:absolute;
    float:right;
    right: 0px;
    text-align: center;
}
.draggable{
    text-align: center;
    width: 100px;
    padding: 10px;
    background-color:#66CCFF;
    cursor:pointer;  
    z-index:100;    
}

脚本:

$(document).ready(function() {
    $("div.draggable").draggable();
    $("div.draggable").mousedown(function() {
        dragID = this.id
    });
    $("div.draggable").mouseup(function() {
        var colliders_selector = ".draggable";
        var obstacles_selector = ".venn";
        var hits = $(colliders_selector).collision(obstacles_selector, {
            mode: "collision"
        });
        alert(hits.text);
    });
});
4

1 回答 1

1

因为您没有调用该函数。

更改alert(hits.text);alert(hits.text());

于 2012-09-10T18:53:44.070 回答