Textarea不是从jQ​​uery生成的

时间:2015-06-21 04:06:23

标签: javascript jquery css

我尝试使用jquery-1.11.1创建一个网站,只要我点击只显示在<textarea> div上的链接,就会产生mouseenter。但我在我的控制台中收到错误,

  

未捕获的ReferenceError:未定义inputdivEditor(请忽略JSFiddle错误)

Error in my page

我完全不知道为什么我会这样做。这是我的代码,

$(document).ready(function () {
    $("[id^=divEditor-]").each(function () {
        var content = $(this).html();
        var targetID = $(this).attr('id');
        var txtID = 'input' + targetID;

        $('<textarea id="input' + targetID + '" name="' + txtID + '" >' + content + '</textarea>').insertBefore(this).css('display', 'none');
        var button = "<a onclick='activateDivEditor(this, " + txtID + ")' class='custom-edit-button editDiv' id='active" + targetID + "'>Embed Code</a>";

        $(this).on('mouseenter', function () {
            $(this).prepend($(button));
            $(this).css('position', 'relative');
        });
        $(this).on('mouseleave', function () {
            $('.editDiv').remove();
        });
    });
});

function activateDivEditor(btn, txtId) {
    var targetID = $(btn).parent().get(0).id;
    var update = "<a onclick='deactivateDivEditor(this, " + txtId + ")' class='custom-edit-button updatediv' id='deactive" + targetID + "'>Update</a>";
    var cancel = "<a onclick='cancelactivateDivEditor(this)' class='custom-edit-button cancel' id='cancelactive" + targetID + "'>Cancel</a>";
    var targetClass = $('#' + targetID).attr('class');
    var targetWidth = $('#' + targetID).width();
    $('#' + targetID).css('display', 'none');
    $('#input' + targetID).css('display', 'block').css('width', targetWidth - 2).css('height', '125px');
    $('#input' + targetID).parent().css('position', 'relative');
    $(update).prependTo($('#input' + targetID).parent());
    $(cancel).prependTo($('#input' + targetID).parent());
}

JSFiddle Demo

每当我点击按钮链接时,如何生成textarea?非常需要这个帮助。感谢。

0 个答案:

没有答案