<script language="javascript" src="./example/jquery.js" type="text/javascript"></script>   
<script language="javascript" type="text/javascript">  
$(document).ready(function(){
    //给td添加click事件
    alert("wwwwwwwww");
     var tdNods = $("td");
     
    tdNods.click(tdClick);});function tdClick()
{
      //得到当前节点对象
        var textNode = $(this);
        //1 得到原来的值
        var textValue = textNode.text();
        //alert(textValue);
        //2 创建 input控件
        var input = $("<input>");
        // 2.5 设置input的属性
        input.attr("value",textValue);
        input.attr("size",4);
        //3 设置textNode的html内容
        textNode.html(input);
        //4 取消td的click事件
         textNode.unbind("click");
        // 5 让所有的文本内容被选中
        input.select();
        //6 键盘事件
        input.keyup(function(event){
            //6.5 根据各个浏览器来获得不同是键盘事件
            var myEvent = event || window.event;
            // 获得键盘Code
            var keyCode = myEvent.keyCode;
            //7 判断按下的是不是回车
            if(keyCode == 13)
            {
                //8 把当前input框的内容获得
                var inputNode = $(this);
                var inputValue = inputNode.val();
                //alert(inputValue);
                //设置textNode的html为 inputValue
                textNode.html(inputValue);
            }
            //判断按下的是不是ESC
            if(keyCode == 27)
            {
//设置成原来的text
               textNode.html(textValue);
            }
        });    //判断input是否失去焦点
    input.blur(function(){
       var inputNode = $(this);
        var inputValue = inputNode.val();
        //alert(inputValue);
        //设置textNode的html为 inputValue
        textNode.html(inputValue);
    });
     //再次调用
     textNode.click(tdClick);
}
</script>
此为编辑表单可编辑的代码

解决方案 »

  1.   

    <thead>
    <tr style="background: url(./images/right_bgbj01.gif) repeat-x;"
    height="27">
    <td width="4%" align="center" >
    <strong>种类</strong>
    </td>
    <td width="4%" align="center">
    <strong>任务号</strong>
    </td>
    <td width="4%" align="center">
    <strong>工装号</strong>
    </td>
    <td width="4%" align="center">
    <strong>型别</strong>
    </td>
    </thead>
    <tbody>
    <logic:notEmpty name="rwresultList">
    <logic:iterate id="list" name="rwresultList">
    <tr>
    <td>
    <bean:write name="list" property="kind" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="id.rwh" />&nbsp;
    </td>
    <td>
    <bean:write name="list" property="id.gzh" />&nbsp;
    </td>
    <td>
    <bean:write name="list" property="xb" />
    &nbsp;
    </td>

    </tr>
    </logic:iterate>
    </logic:notEmpty> </tbody>这个是表单内容 我现在上面的编辑表单只能编辑表头名称,而我想可编辑查询出来的表体内容,该如何修改呢?
      

  2.   

    最简单的方法,点要修改的地方,触发一个js事件,清空对应的td中的内容,添加新的input,把对应的值赋值到input中,你就可以修改了 呵呵
      

  3.   

    就按照我上面写的编辑表单的JS那么写,我只能改表头的内容,也就是说只能修改表头名称,不能修改查询出来的值啊,如果按你的方式写的话,该如何修改我上面的JS脚本呢