`
op_xiaoyang
  • 浏览: 9805 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
文章分类
社区版块
存档分类
最新评论

jquery js 可编辑表格

 
阅读更多
/*
 * 可编辑表格
 * @author 肖杨
 * 基于jquery
 * 需要 绘制一个表格td id=list 主键标识  input test 初始隐藏,id=input_主键标识
 * 如:<td>
						<span id="movieAge_<s:property value="movieId"/>" ondblclick="tdclick(this)">
						<s:property value="movieAge"/>
						</span>
						<span><input id="input_movieAge_<s:property value="movieId"/>" style="display: none;" 
							onblur="inputBlur(this)" name="oa.movieAge"/></span>
						<span><input value="<s:property value="movieAge"/>" 
							type="checkbox" id="checkbox_movieAge_<s:property value="movieId"/>"
							 style="display: none;" 
							 name="movieAge"/></span>
					</td>
 */
$( function() {
	$("input[id^='input_']").each( function() {
		$(this).keydown( function(event) {
			if (event.keyCode == 13) {
				inputBlur(this);
				return false;
			}

		})
	});
});
function tdclick(text) {// 双击
	// 隐藏本身
	text.style.display = "none";
	// 显示隐藏的input
	var tid = text.id;
	var inputtemp = document.getElementById("input_" + tid);
	inputtemp.value = text.innerHTML;
	inputtemp.style.display = "block";

}
// 失去焦距
function inputBlur(text) {
	// 取得td
	var temp = text.id;
	var inputid = temp.substring(6, temp.length);
	// 赋值
	var inputtemp = document.getElementById(inputid);
	inputtemp.innerHTML = text.value;

	// 启用box模式,用来往后台传数组
	forChebox(inputid, text.value);
	// 移开 隐藏input 赋值本身
	text.style.display = "none";
	inputtemp.style.display = "block";
}

function forChebox(id, value) {
	var checkboxid = "checkbox_" + id;
	var boxtemp = document.getElementById(checkboxid);
	boxtemp.value = value;
}

function boxClick(check, id) {
	var temp = "input[id$='_" + id + "'][type=checkbox]";
	if (check.checked) {
		$(temp).attr("checked", true);
	} else {
		$(temp).attr("checked", false);
	}
}

昨天要用这个,没发现好用的,就自己写了个通用的,大家可以参考参考。

使用例子:

  <form action="indent_oaInter.action" method="post" id="indentsform">
		<table width="100%"  class="table_list">
			<tr class="table_01">
				<th scope="col">选择</th>
				<th scope="col">影片姓名</th>
				<th scope="col">影片类型	</th>
				<th scope="col">时长	</th>
				<th scope="col">字幕语种	</th>
				<th scope="col">声道语种	</th>
				<th scope="col">国家和地区</th>
				<th scope="col">影片年份</th>
			</tr>
			
			<s:iterator value="list" status="status">
				<tr align="center" bgcolor="#E0E0E0">
					<td>
						<input name="clickrow" type="checkbox" value="<s:property value="movieId"/>" name="allcheck"  onclick="boxClick(this,<s:property value="movieId"/>)"/>
							<input type="checkbox" value="<s:property value="movieId"/>" 
							id="checkbox_movieId_<s:property value="movieId"/>" name="movieId"
							style="display: none;"/>
					</td>
					<td>
						<span id="movieName_<s:property value="movieId"/>" ondblclick="tdclick(this)">
						<s:property value="movieName"/>
						</span>
						<span><input id="input_movieName_<s:property value="movieId"/>" style="display: none;" 
							onblur="inputBlur(this)" value="<s:property value="movieName"/>" name="oa.movieName"/></span>
						<span>
							<input type="checkbox" value="<s:property value="movieName"/>" 
							id="checkbox_movieName_<s:property value="movieId"/>" name="movieName"
							style="display: none;"/>
							</span>
					</td>
					
					<td>
						<span id="movieType_<s:property value="movieId"/>" ondblclick="tdclick(this)">
						<s:property value="movieType"/>
						</span>
						<span><input value="<s:property value="movieType"/>" 
						id="input_movieType_<s:property value="movieId"/>" style="display: none;" 
							onblur="inputBlur(this)" name="oa.movieType"/></span>
							<span><input value="<s:property value="movieType"/>" 
							type="checkbox" id="checkbox_movieType_<s:property value="movieId"/>"
							 style="display: none;" 
							 name="movieType"/></span>
					</td>
					<td>
						<span id="movieTimeLength_<s:property value="movieId"/>" ondblclick="tdclick(this)">
						<s:property value="movieTimeLength"/>
						</span>
						<span><input id="input_movieTimeLength_<s:property value="movieId"/>" style="display: none;" 
							onblur="inputBlur(this)" value="<s:property value="movieTimeLength"/>" name="oa.movieTimeLength"/></span>
							<span><input value="<s:property value="movieTimeLength"/>" 
							type="checkbox" id="checkbox_movieTimeLength_<s:property value="movieId"/>"
							 style="display: none;" 
							 name="movieTimeLength"/></span>
					</td>
					
					<!-- 字幕 -->
					<td>
						<span id="languageType_<s:property value="movieId"/>" ondblclick="tdclick(this)">
						<s:property value="languageType"/>
						</span>
						<span><input id="input_languageType_<s:property value="movieId"/>" style="display: none;" 
							onblur="inputBlur(this)" value="<s:property value="languageType"/>" name="oa.languageType"/></span>
								<span><input value="<s:property value="languageType"/>" 
							type="checkbox" id="checkbox_languageType_<s:property value="movieId"/>"
							 style="display: none;" 
							 name="languageType"/></span>
					</td>
					<!-- 声道 -->
					<td>
						<span id="track<s:property value="movieId"/>" ondblclick="tdclick(this)">
						<s:property value="track"/>
						</span>
						<span><input id="input_track_<s:property value="movieId"/>" style="display: none;" 
							onblur="inputBlur(this)" name="oa.track"/></span>
							
							<span><input id="input_track_<s:property value="movieId"/>" style="display: none;" 
							onblur="inputBlur(this)" value="<s:property value="languageType"/>" name="oa.track"/></span>
								<span><input value="<s:property value="track"/>" 
							type="checkbox" id="checkbox_track_<s:property value="movieId"/>"
							 style="display: none;" 
							 name="track"/></span>
					</td>
					
					<td>
						<span id="area_<s:property value="movieId"/>" ondblclick="tdclick(this)">
						<s:property value="area"/>
						</span>
						<span><input id="input_area_<s:property value="movieId"/>" style="display: none;" 
							onblur="inputBlur(this)" name="oa.area"/></span>
							<span><input value="<s:property value="area"/>" 
							type="checkbox" id="checkbox_area_<s:property value="movieId"/>"
							 style="display: none;" 
							 name="area"/></span>
					</td>
					
					<td>
						<span id="movieAge_<s:property value="movieId"/>" ondblclick="tdclick(this)">
						<s:property value="movieAge"/>
						</span>
						<span><input id="input_movieAge_<s:property value="movieId"/>" style="display: none;" 
							onblur="inputBlur(this)" name="oa.movieAge"/></span>
						<span><input value="<s:property value="movieAge"/>" 
							type="checkbox" id="checkbox_movieAge_<s:property value="movieId"/>"
							 style="display: none;" 
							 name="movieAge"/></span>
					</td>
				</tr>
											</s:iterator>
		</table>
		<input type="button" value="提交" onclick="TJsub()"/>	
		</form>



如图:

分享到:
评论

相关推荐

    利用JQuery实现可编辑的表格

    利用JQuery,实现一个可编辑的表格,同时可以修改表格内容!

    jQuery自适应PC手机端可编辑表格代码.zip

    &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;meta name="viewport" content="width=device-width,... 一款简洁实用的自适应PC手机端的jQuery可编辑表格代码,jQuery表格添加删除行数据代码,使用起来十分的方便。

    jQuery实现的可编辑表格完整实例

    本文实例讲述了jQuery实现的可编辑表格。分享给大家供大家参考,具体如下: &lt;!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd&gt; &lt;html&gt; &lt;head&gt; &lt;meta ...

    基于Bootstrap使用jQuery实现简单可编辑表格

    editTable.js 提供编辑表格当前行、添加一行、删除当前行的操作,其中可以设置参数,如: operatePos 用于设置放置操作的列,从0开始,-1表示以最后一列作为放置操作的列;(这里的操作包括 编辑当前行、在当前行下...

    用jquery编辑的可更改表格内容的斑马表

    用jquery编辑的可更改表格内容的斑马表

    jQuery实现可编辑表格并生成json结果(实例代码)

    主要介绍了 jquery实现可编辑表格并生成json结果,该代码解析和加载功能都用前端js实现,简化了后台代码逻辑,非常不错,具有参考借鉴加载,需要的朋友可以参考下

    jQuery实现可以编辑的表格实例详解【附demo源码下载】

    今天小编主要给大家讲解一下,如何利用jQuery+js+css实现表格的编辑。接下来,小编就简单总结一下如何实现这个小例子。 第一步:编写html代码,代码如下所示: &lt;!DOCTYPE ...

    基于jQuery和PureCSS的可编辑表格

    今天要介绍的一款jQuery是一个可编辑的表格,它的实现非常简单,主要利用了jQuery插件和PureCSS插件,简单的引用和初始化JavaScript语句即可让网页上的table表格可以自定义编辑,非常实用。

    自适应PC手机端的C3 jQuery可编辑表格代码.zip

    代码片段: 姓名 性别 年龄 电话 操作 &lt;td colspan="5" class="danger"&gt;&lt;button class="btn btn-primary btn-sm"&gt;增加&lt;/button&gt;&lt;/td&gt; &lt;/table&gt;

    js实现可以编辑的表格

    自己用jQuery写的可以让table实现可以编辑和保存,可以大大的提高用户体验。js文件注有注释,非常容易理解。

    用Jquery实现可编辑表格并用AJAX提交到服务器修改数据

    下面是js Code: 代码如下: $(function() { // 相当于在页面中的body标签加上onload事件 $(“.caname”).click(function() { // 给页面中有caname类的标签加上click函数 var objTD = $(this); var oldText = $.trim...

    基于jQuery实现可编辑的表格

    我们知道jQuery是一个轻便的JavaScript框架,里面封装了系统和程序常用到的一些方法,利用CSS、HTML可以将这些内容运用起来,做出各式各样好看的界面,下面小编使用jQuery实现了一个“可编辑的表格”的例子。...

    Jquery可编辑表格插件DataTables-1.7.6.zip

    DataTables-1.7.6.zipDataTables-1.7.6.zipDataTables-1.7.6.zipDataTables-1.7.6.zipDataTables-1.7.6.zipDataTables-1.7.6.zipDataTables-1.7.6.zipDataTables-1.7.6.zipDataTables-1.7.6.zipDataTables-1.7.6.zip

    jQuery表格内容修改删除代码.zip

    jQuery表格内容修改删除代码是一款基于Bootstrap制作可编辑的表格插件,点击图标按钮可以对表格进行编辑,支持将该表格行删除增加效果代码。

    jquery.PrintArea.js实现打印发货单功能

    本项目用jquery.PrintArea.js实现打印功能,实现一个打印发货单的功能。主要用div和table来实现,可以运行

    BootStrap和jQuery相结合实现可编辑表格

    editTable.js 提供编辑表格当前行、添加一行、删除当前行的操作,其中可以设置参数,如: operatePos 用于设置放置操作的列,从0开始,-1表示以最后一列作为放置操作的列;(这里的操作包括 编辑当前行、在当前行下...

    可编辑的表格

    引用jQuery框架和本此js,可以使表格可编辑,可设置输入提示框,可设置行变色,使用说明都在js文件中

    可编辑表格

    使用Jquery实现表格的可编辑,双击单元格即可编辑单元格中的内容。

    Jquery 实现列的拖动 jquery grid

    jquey 实现grid 的列的自由拖动 和内容的自由展示和压缩 类似于excel效果。

Global site tag (gtag.js) - Google Analytics