Jquery实现双击表单元格可编辑

 

<script type="text/javascript">
function doTableTdEditClick(param){
    doTdEditable(param);
}
function doTdEditable(param){
    var input ="<input type='text' id='temp' value='"+$(param).text()+"' />";
    $(param).text("").append(input);
    var inputObj = $(param).find("input");
    inputObj.focus();
    inputObj.dblclick(function(){
        inputObj.blur();
        return;
    });
    inputObj.blur(function(){
        if($(this).val()==""){
            $(this).closest("td").text(" ");
        }else{
            $(this).closest("td").text($(this).val());
        }
        return;
    });
}
$("table.tableTdEdit").find("TD.cellEdit").each(function(index,domEle){
    $(domEle).css("background","#3A96F6");
    $(domEle).attr("ondblclick","doTableTdEditClick(this);");
    return;
});
</script>
posted @ 2015-05-26 21:16  Hypocrite  阅读(789)  评论(0编辑  收藏  举报