//修改单元格内容 jQuery(document).on('dblclick','#tab tbody tr td:not([class="checkGroup"])',function(event){ //获得窗口的宽度 高度 var winW=document.body.clientWidth; var winH=document.body.clientHeight; alert("窗口的宽高:"+winH+"><"+winW); //获得鼠标点击时的坐标 var pointX = window.event.clientX; var pointY = window.event.clientY; //获得弹出div的高 宽 var runDivH = $('#runDiv').height(); var runDivW =$('#runDiv').width(); //计算弹出div的位置 var x = ((pointX-runDivW/2)>0)?(pointX-runDivW/2):0; var y = ((pointY-runDivH/2)>0)?(pointY-runDivH/2):0; x = ((x+runDivW)>winW)?(winW-runDivW):x; y = ((y+runDivH)>winH)?(winH-runDivH):y; //获得单元格的内容 var text = $(event.target).text(); var tdObj = $(event.target); //设置弹出div的位置 $("#runDiv").css("left",x); $("#runDiv").css("top",y); $("#runDiv").show(); $('#newText').focus().text(text).select(); $('#runDiv button').click(function(){ var saveBtnName = $('#runDiv button[name^="save"]').attr('name'); var btnName = $(this).attr('name'); if(btnName==saveBtnName){ var newStr = $('#newText').val(); tdObj.text(newStr); } $("#runDiv").hide(); }); });