---
title: "jquery 双击表格单元格编辑输入"
author: "ThinkGoogle"
date: "2012-09-03T14:12:13Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2012-09-03T14:12:13Z"
id: 1670443
url: "https://thinkgoogle.iteye.com/blog/1670443"
---

```
	 	$("#table").find("td").bind("dblclick",function(){
	 		var input ="<input type='text' id='temp' value="+$(this).text()+" >";
	 		$(this).text("");
	 		$(this).append(input);
	 		$("input#temp").focus();
	 		$("input").blur(function(){
	 			if($(this).val()==""){
	 				$(this).remove();
	 			}else{
	 				$(this).closest("td").text($(this).val());
	 			}
	 		});
```

 

```
   	<table border="1" width="200" id="table">
		<tr><td>111</td></tr>
		<tr><td>222</td></tr>
		<tr><td>333</td></tr>
		<tr><td>444</td></tr>
		<tr><td>555</td></tr>
 	</table>
```

 ![xx](http://dl.iteye.com/upload/attachment/0073/2439/f0090717-780a-3503-bedd-ae93895652bc.png)