jquery将图像的属性拖放到textarea中 [英] jquery drag and drop image's attribute into textarea

查看:104
本文介绍了jquery将图像的属性拖放到textarea中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试拖放功能时,我遇到问题。我需要将图像拖动到textarea中,当删除时,该文本将附加在data-twname自定义html属性中存储的twitter用户名。

I've been having a problem while testing drag and drop functionality. I need images to be draggable into a textarea, and when dropped, the text would be appended by a twitter username stored inside "data-twname" custom html attribute.

问题当我在textarea内键入文本时,会出现 - 任何后续的drag& drop都不会将twitter名称附加到文本,即使它在开始工作。这是我使用的jQuery代码:

Problem appears when I type text inside the textarea - any subsequent drag&drop simply does not append twitter name to the text, even though it works in start. This is the jQuery code I use:

$(".draggie").draggable({
    containment: "parent",
    cursor: "move",
    revert: true,
    revertDuration: 100
});
var targetName;
$(".draggie").mousedown(function(){
    targetName = $(this).attr("data-twimage");
});
$("#textCompose").droppable({
    accept: ".draggie",
    drop: function(event) {
        $("#textCompose").append(targetName);
    }
});

我在这里做了一个演示,以澄清:删除演示链接

I've made a demo here, to clarify: drop demo link

推荐答案

认为你的意思是你不能附加值,以防你已经插入了一些文本。我在这里创建了一个小提琴: http://jsfiddle.net/QQWHg/

I think you mean you can't append the value in case you already inserted some text. I created an fiddle for your example here: http://jsfiddle.net/QQWHg/

替换:

$("#textCompose").append(targetName);

with:

$('#textCompose').val($('#textCompose').val() + targetName);

这篇关于jquery将图像的属性拖放到textarea中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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