jquery绑定按钮显示在textarea上

jquery绑定按钮显示在textarea上,jquery,binding,Jquery,Binding,首先,这里是我遇到问题的脚本链接: 我的剧本 单击图像上的任意位置以创建注释,该部分工作正常。 当您单击现有注释并添加注释时,它会起作用,但当您尝试添加其他注释时,它不会起作用。有人能帮我做一下装订吗 编辑: 输入注释后,转到另一个选项卡/注释不显示添加注释框 我的js源代码 $(document).ready(function() { getComments(); var imgClass = "proof", bodyEle =

首先,这里是我遇到问题的脚本链接:

我的剧本

单击图像上的任意位置以创建注释,该部分工作正常。 当您单击现有注释并添加注释时,它会起作用,但当您尝试添加其他注释时,它不会起作用。有人能帮我做一下装订吗

编辑: 输入注释后,转到另一个选项卡/注释不显示添加注释框

我的js源代码

$(document).ready(function() {

        getComments();

        var imgClass = "proof",
            bodyEle = $('img.' + imgClass).parent(),
            id = 0,
            currentDot,
            currentDiv,
            tabAdded = false,
            currentTabID,
            viewingTab = false,
            status = false;

        /*$("img." + imgClass).mouseover(function( ){
            $(this).css("cursor", "url(lib/images/cursor-2.png)");
            console.log('hmmm');
        });
        $("div.proof_container").on('click', function(){
            if(status){
                $("#nDiv_" + (id - 1)).remove();
                $("#nDot_" + (id - 1)).remove();
            }
        });*/
        $("img." + imgClass).on("click", function(event){

            if(viewingTab){
                $('.nBox').each(function(){
                    $(this).hide();
                });
                viewingTab = false;
            }

            var offset = $(this).offset(),
                leftE = (event.clientX - offset.left),
                topE = (event.clientY - offset.top);

            //error testing
            /*
            console.log('Offset: ' + offset);
            console.log('Left: ' + leftE);
            console.log('Top: ' + topE);
            */

            var newCon = $('<div class="com_container"></div>'),
                newDot = $('<img src="lib/img/circle.png" width="25px" height="25px" class="nDot" />'),
                newDiv = $('<div class="nBox"></div>'),
                newForm = $('<form name="nForm" id="nForm" method="post"></form>'),
                newText = $('<textarea name="nText" class="nText"></textarea>'),
                newLeft = $('<input type="hidden" class="nLeft" name="nLeft" />'),
                newTop = $('<input type="hidden" class="nTop" name="nTop" />'),
                newButton = $('<input type="button" name="nButton" value="Add Comment" />');

            if(status == false){

                //css
                newDot.css({
                    'position': 'absolute',
                    'left': (leftE + 3),
                    'top': (topE - 13)
                });
                newDiv.css({
                    'position': 'absolute',
                    'left': (leftE + 24),
                    'top': (topE + 8)
                });

                //id's
                newDot.attr('id', 'nDot_' + id);
                newDiv.attr('id', 'nDiv_' + id);

                //set currents
                currentDiv = $("#nDiv_" + id);
                currentDot = $("#nDot_" + id);
                id++;


                newDiv.append(newForm);
                newForm.append(newText);
                newForm.append(newLeft);
                newForm.append(newTop);
                newForm.append(newButton);
                newButton.hide();


                newLeft.val(leftE);
                newTop.val(topE);

                bodyEle.append(newDot);
                bodyEle.append(newDiv);

                status = true;


                //textarea change
                newText.bind('input propertychange', function() {
                    if($(this).val() == ""){
                        newButton.hide();
                    }
                    else{
                        newButton.show();   
                    }
                });

                //button submit
                $(newButton).on('click', function( ){
                    //check to see if tab has already been added
                    if(tabAdded == false){
                        //create tab
                        $.get("createTab.php", {left: leftE, top: topE}).done(function(data){
                            var obj = $.parseJSON(data);
                            tabAdded = true;
                            currentTabID = obj.tab;
                            //create comment
                            $.post("test_add.php", {comment: newText.val(), tab_id: currentTabID}).done(function(data){

                                //getName
                                $.get("get_name.php").done(function(data){

                                    var obj = $.parseJSON(data);

                                    var newComment = $('<div class="comm">' + newText.val() + '<br />-' + obj.name + '</div>');
                                    newForm.before(newComment);
                                    newButton.hide();
                                    newText.val("");

                                });

                                getComments();
                                return;

                            });
                        });
                    }
                    else{
                        $.post("test_add.php", {comment: newText.val(), tab_id: currentTabID}).done(function(data){

                            //getName
                            $.get("get_name.php").done(function(data){

                                var obj = $.parseJSON(data);

                                var newComment = $('<div class="comm">' + newText.val() + '<br />-' + obj.name + '</div>');
                                newForm.before(newComment);
                                newButton.hide();
                                newText.val("");

                            });

                            getComments();
                            return;

                        });
                    }

                });
            }
            else{

                if(tabAdded){
                    $("#nDiv_" + (id - 1)).remove();
                    tabAdded = false;
                    currentTabID = "";
                }
                else{

                    $("#nDiv_" + (id - 1)).remove();
                    $("#nDot_" + (id - 1)).remove();
                }

                status = false;
            }


        });


        function getComments(){

            var project_id = '1'; //testing purpose

            $.get( "get_comments.php", { project_id: project_id }).done(function( data ) {
                var obj = $.parseJSON(data);

                //testing info
                console.log(obj);

                for(var i = 0; i < obj.length; i++){

                    var newTabLeft = obj[i].tab.left,
                        newTabTop = obj[i].tab.top,
                        newTabID = obj[i].tab.comment_id;
                        newTabDot = $('<img id="tab_' + newTabID + '" src="lib/img/circle.png" width="25px" height="25px" class="TDot" />'),
                        newTabDiv = $('<div id="tabDiv_' + newTabID + '" class="nBox"></div>'),
                        newTabForm = $('<form name="nForm" id="nForm_' + newTabID + '" method="post"></form>'),
                        newTabText = $('<textarea name="nText" id="nText_' + newTabID + '" class="nText"></textarea>'),
                        newTabLeftInput = $('<input type="hidden" id="nLeftInput_' + newTabID + '" class="nLeft" name="nLeft" />'),
                        newTabTopInput = $('<input type="hidden" id="nTopInput_' + newTabID + '" class="nTop" name="nTop" />'),
                        newTabIDInput = $('<input type="hidden" id="nIDInput_' + newTabID + '" class="nTop" name="nTabID" />'),
                        newTabButton = $('<input type="button" id="nButton_' + newTabID + '"name="nButton" value="Add Comment" />');

                    //css
                    newTabDot.css({
                        'position': 'absolute',
                        'left': (parseInt(newTabLeft) + 3),
                        'top': (parseInt(newTabTop) - 13)
                    });
                    newTabDiv.css({
                        'position': 'absolute',
                        'left': (parseInt(newTabLeft) + 24),
                        'top': (parseInt(newTabTop) + 8)
                    });

                    newTabDiv.append(newTabForm);
                    newTabForm.append(newTabText);
                    newTabForm.append(newTabLeftInput);
                    newTabForm.append(newTabTopInput);
                    newTabForm.append(newTabIDInput);
                    newTabForm.append(newTabButton);
                    newTabDiv.hide();
                    newTabButton.hide();

                    bodyEle.append(newTabDot);
                    bodyEle.append(newTabDiv);

                    //addcomments before form
                    for(var x = 0; x < obj[i].comments.length; x++){

                        var newCommentBox = $('<div class="comm">' + obj[i].comments[x].comment + '<br /> - ' + obj[i].comments[x].client_name + '</div>');
                        newTabForm.before(newCommentBox);


                    }

                    //textarea change
                    $('#nText_' + newTabID).on('input propertychange', function() {
                        console.log('being changed');
                        if($(this).val() == ""){
                            $('#nButton_' + newTabID).hide();
                        }
                        else{
                            $('#nButton_' + newTabID).show();   
                        }
                    });


                    $("img.TDot").on('click', function(){

                        if(status){
                            console.log('This Is Being Called');
                            $(".nDot").each(function(){
                                $(this).remove();
                            });
                        }

                        $('.nBox').each(function(){
                            $(this).hide();
                        });


                        var id = $(this).attr('id');
                        var newId = id.split("_");

                        $('#tabDiv_' + newId[1]).show();
                        viewingTab = true;
                    }).on('mouseover', function(){
                        $(this).css('cursor', 'pointer');
                    });

                    newTabButton.on('click', function(){

                        $.post("test_add.php", {comment: newTabText.val(), tab_id: newTabID}).done(function(data){

                            //getName
                            $.get("get_name.php").done(function(data){

                                var obj = $.parseJSON(data);

                                var newComment = $('<div class="comm">' + newTabText.val() + '<br /> - ' + obj.name + '</div>');
                                newTabForm.before(newComment);
                                newTabButton.hide();
                                newTabText.val("");

                                $('nText_' + newTabID).bind('input propertychange', function() {

                                    if($(this).val() == ""){
                                        $('nButton_' + newTabID).hide();
                                    }
                                    else{
                                        $('nButton_' + newTabID).show();    
                                    }
                                });

                            });

                            getComments();
                            return;

                        });

                    });
                }
            });

        }
    });// JavaScript Document
$(文档).ready(函数(){
getComments();
var imgClass=“证明”,
bodyEle=$('img.+imgClass).parent(),
id=0,
当前点,
当前部门,
tabAdded=false,
当前选项卡,
viewingTab=false,
状态=假;
/*$(“img.+imgClass).mouseover(函数(){
$(this.css(“cursor”,“url(lib/images/cursor-2.png)”);
console.log('hmmm');
});
$(“div.proof_container”)。在('click',function()上{
如果(状态){
$(“#nDiv"”+(id-1)).remove();
$(“#nDot"”+(id-1)).remove();
}
});*/
$(“img.”+imgClass)。在(“单击”)上,函数(事件){
如果(查看选项卡){
$('.nBox')。每个(函数(){
$(this.hide();
});
viewingTab=false;
}
var offset=$(this).offset(),
leftE=(event.clientX-offset.left),
topE=(event.clientY-offset.top);
//错误测试
/*
console.log('Offset:'+Offset);
log('Left:'+leftE);
console.log('Top:'+topE);
*/
var newCon=$(''),
newDot=$(''),
newDiv=$(''),
新形式=$(''),
新文本=$(''),
newLeft=$(''),
newTop=$(''),
纽扣=$('');
如果(状态==false){
//css
newDot.css({
'位置':'绝对',
“left”:(leftE+3),
“top”:(topE-13)
});
newDiv.css({
'位置':'绝对',
“left”:(leftE+24),
“顶部”:(顶部+8)
});
//身份证
newDot.attr('id','nDot_'+id);
newDiv.attr('id','nDiv_'+id);
//设定电流
currentDiv=$(“#nDiv”+id);
currentDot=$(“#nDot”+id);
id++;
newDiv.append(newForm);
newForm.append(newText);
newForm.append(newLeft);
newForm.append(newTop);
newForm.append(newButton);
newButton.hide();
val(leftE);
新梢val(topE);
bodyEle.append(newDot);
bodyEle.append(newDiv);
状态=真;
//文本区域更改
newText.bind('InputPropertyChange',function(){
if($(this).val()==“”){
newButton.hide();
}
否则{
show();
}
});
//按钮提交
$(新按钮)。在('click',函数(){
//检查是否已添加选项卡
if(tabAdded==false){
//创建选项卡
$.get(“createTab.php”,{left:leftE,top:topE}).done(函数(数据){
var obj=$.parseJSON(数据);
tabAdded=true;
currentTabID=obj.tab;
//创建注释
$.post(“test_add.php”,{comment:newText.val(),tab_id:currenttab id}).done(函数(数据){
//getName
$.get(“get_name.php”).done(函数(数据){
var obj=$.parseJSON(数据);
var newComment=$(''+newText.val()++'
-'+obj.name+''); 新形式。之前(新出现); newButton.hide(); newText.val(“”); }); getComments(); 回来 }); }); } 否则{ $.post(“test_add.php”,{comment:newText.val(),tab_id:currenttab id}).done(函数(数据){ //getName $.get(“get_name.php”).done(函数(数据){ var obj=$.parseJSON(数据); var newComment=$(''+newText.val()++'
-'+obj.name+''); 新形式。之前(新出现); newButton.hide(); newText.val(“”); }); getComments(); 回来 }); } }); } 否则{ 如果(已添加){ $(“#nDiv"”+(id-1)).remove(); tabAdded=false; currentTabID=“”; } 否则{ $(“#nDiv"”+(id-1)).remove(); $(“#nDot"”+(id-1)).remove(); } 状态=假; } }); 函数getComments(){ var pro