table表格中单击添加动态编辑框

    var $newNode=$("<input type='text' style='width:250px; height:20px; maxlength='20' id='textinput' onclick='doSomething(this,event)' >");
    var $oldTdObj="";   //用于保存TD对象

 $(function(){
            
            $(".wendu").click(function(){
                //获取当前TD的值
                var $oldValue = $(this).text();
                //是否存在input
                var $ifInput = $(this).children().is('input');
                if($oldTdObj != ""){
                    var newValue = $("#textinput").val();
                    if(typeof(newValue) != "undefined"){
                        $oldTdObj.text(newValue);
                        console.log(newValue);
                        //param = newValue;
                    }
                }
               // <!--如果TD单元格中不存在input,则添加-->
                if(!$ifInput){
                    $(this).text('');
                    $oldTdObj = $(this);
                    $(this).append($newNode);
                    $newNode.val($oldValue);
                    $newNode.focus();
                }
            });

  });

 

posted @ 2017-08-09 10:30  yunxu  阅读(684)  评论(0编辑  收藏  举报