jQuery拖放-单击事件寄存器 [英] Jquery drag and drop - click event registers on drop

查看:98
本文介绍了jQuery拖放-单击事件寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery拖放.可拖动元素是一个div,其中两个嵌套的div左右浮动.放下时,将为左侧嵌套div(包含文本)启用click事件:

I'm using jquery drag and drop. The draggable element is a div with two nested divs floated left and right. On drop, the left nested div (which contains the text), gets enabled for a click event:

$('.element_left').click(function(e) {  
        window.open(ui.draggable.attr('data-link'));
});

现在放下时,会触发click事件,以打开可拖动对象的数据链接中的链接.当可拖动的编号与广告位编号不匹配时,它似乎会触发,但在此位置不是100%.

Now on drop, sporadically, the click event fires off opening the link in the data-link for the draggable. It looks like it fires off when the draggable number doesn't match the slot number, but not 100% on this.

http://jsfiddle.net/f2bbt/

怪异...您可能需要尝试几次才能发生这种情况,将元素拖动到插槽的边缘,以便插槽突出显示.紧接在提取RNA"下方的可拖动对象似乎比其他操作更多...并且在发生错误的页面加载时……应该是element_8.html,但是相反,它为element_1.html打开了一个新页面(属于孤立病毒元素).

Weird... You may need to try a few times to get this happening, drag the element to the edge of the slot so that the slot highlights. The draggable immediately below the 'Extract RNA' seems to do this more than others...and when it happens the wrong page is loaded...should be element_8.html, but instead it opens a new page for element_1.html (which belongs to Isolate Virus element).

推荐答案

看起来您想要做的就是将点击处理程序添加到放置的元素中,而不是将点击处理程序添加到所有元素中类别为element_left

It looks like what you want to do is to add the click handler to the element which was dropped, instead of that you were adding the click handler to all elements with class element_left

您需要将其更改为

ui.draggable.click(function(e) {  
    window.open(ui.draggable.attr('data-link'));
});

演示:小提琴

这篇关于jQuery拖放-单击事件寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆