<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>jquery示例3:可修改的表格</title>
   
<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></head>
<body>
    <table border="1">
        <tbody>
           <tr>               <td>1234</td>
               <td>5678</td>
           </tr>
        </tbody>
    </table>
</body>
</html>

解决方案 »

  1.   

    你使用了$(document),但是你引入了jQuery的库吗?能解释$吗?
      

  2.   

    1楼说得对,楼主的jQuery库还没引入。
      

  3.   

    引入jQuery的类库。就像引入一个JS文件一样:<script language="javascript" src="${pageContext.request.contextPath}/script/jquery.js"></script>
    注意放的顺序
      

  4.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
      <title>jquery示例3:可修改的表格</title>
        
    <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内容
      textNodewww.cctv40.cn.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></head>
    <body>
      <table border="1">
      <tbody>
      <tr>  <td>1234</td>
      <td>5678</td>
      </tr>
      </tbody>
      </table>
    </body>
    </html>
    好像行