2014-01-21 21 views
-1

我想創建一個表,可以通過點擊它來修改它的內容,出現輸入框,如果它沒有對焦,它會再次回到一個文本(我在裏面做了一個跨度元素)jQuery Table Live Edit

$arr = array("fname", "lname", "company", "jobtitle", "category", "email", "phonenumber", "mobilenumber", "remarks"); 
      foreach ($arr as &$value) { 
        echo " 
        $('.$value').click(function() { 
         $(this).replaceWith(function() { 
           return \"<span class='{$value}3'><input class='{$value}2' style = 'width:100%' name= '$value' value=\"+ \"'\"+$(this).text() + \"'\"+ \"/></span>\";   
         }); 
        }); 
        "; 

        echo " 
         $('.{$value}2').blur(function() { 
          $('.{$value}3').replaceWith(function() { 
            return \"<span class='$value'>$value</span>\"; 
          }); 
         }); 
        "; 
     } 
     ?> 

回答

0

嘗試替換你在那裏的行。它驅使我。

return \"<span class='{$value}3'><input class='{$value}2' style = 'width:100%' name= '$value' value='\"+ $(this).text() + \"' /></span>\";