使用拖放插件触摸手势时setData未定义(但适用于桌面Chrome)

时间:2017-09-10 01:18:00

标签: jquery image mobile drag-and-drop data-transfer

我目前正在努力在移动设备上实现拖放功能。幸运的是,我找到了一个合适的解决方案here。我仍然遇到的问题是这个错误:

Uncaught TypeError: Cannot read property 'setData' of undefined

仅当我在chromes dev模式下使用移动模式时(按F12),才会出现此错误。在正常模式下,代码可以正常工作,并且“数据”设置为“正常”。获得认可

    $(document).ready(function(){
            for(var i=1;i<=12;i++) {
                $('#img' + i).quickdroppable('draggable', {}, function (ev) {
                    ev.dataTransfer.setData("src", ev.target.id);
                    var number = ev.target.id.replace(/[^\d.]/g, '');
                    ev.dataTransfer.setData("text/plain", number);
                });
            }
    })(jQuery);

HTML也不是特别的:

<div>
            <div class="inline-block field" id="preview5" style="margin-bottom:5px" >
                <img class="img-responsive border-blue image-cover" id="img5" src="img/cubthumbs/cub5.jpg" />
            </div><br>
            <?php for($i=4;$i>=1;$i--):?>
                <div class="inline-block field" id="preview<?php echo $i?>" >
                    <img class="img-responsive border-blue image-cover" id="img<?php echo $i?>" src="<?php echo 'img/cubthumbs/cub'.$i.'.jpg';?>"/>
                </div>
            <?php endfor; ?><br>
            <div class="inline-block field" id="preview6">
                <img class="img-responsive border-blue image-cover" id="img6" src="img/cubthumbs/cub6.jpg" />
            </div>
        </div>

也许有人使用移动功能遇到过类似问题......

0 个答案:

没有答案