Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将可拖动div的HTML插入textarea';s在jquery中的具体位置_Jquery_Jquery Ui - Fatal编程技术网

将可拖动div的HTML插入textarea';s在jquery中的具体位置

将可拖动div的HTML插入textarea';s在jquery中的具体位置,jquery,jquery-ui,Jquery,Jquery Ui,我想将draggable div的html插入textarea的特定位置 有一些可拖动的div,我想将div拖动到文本区域,当我释放鼠标左键时,div html()将自动附加到文本区域的光标位置 有什么解决办法吗 我的代码 $('#datasource-column-container').find('ul > li').each(function (i, element) { $(element).draggable({ revert: "invalid",

我想将draggable div的html插入textarea的特定位置

有一些可拖动的div,我想将div拖动到文本区域,当我释放鼠标左键时,div html()将自动附加到文本区域的光标位置

有什么解决办法吗

我的代码

$('#datasource-column-container').find('ul > li').each(function (i, element) {

    $(element).draggable({
        revert: "invalid",
        helper: "clone",
        connectToSortable: '#template-htmlarea',
        zIndex: 999,
        stop: function () {
            // alert($(element).html());
            // $('#template-htmlarea').html($(element).html());
            $('#template-htmlarea').insertAtCaret($(element).html());
        }
    });

    //$(element).sortable();
});

$.fn.extend({
    insertAtCaret: function (myValue) {
        if (document.selection) {
            this.focus();
            sel = document.selection.createRange();
            sel.text = myValue;
            this.focus();
        } else if (this.selectionStart || this.selectionStart == '0') {
            var startPos = this.selectionStart;
            var endPos = this.selectionEnd;
            var scrollTop = this.scrollTop;
            this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos, this.value.length);
            this.focus();
            this.selectionStart = startPos + myValue.length;
            this.selectionEnd = startPos + myValue.length;
            this.scrollTop = scrollTop;
        } else {
            this.value += myValue;
            this.focus();
        }
    }
});

告诉我们你现在做了什么?你好RahulB我发了我的代码