js 克隆行、删除行

js 克隆行、删除行

前言

现在项目中,由于本人负责的模块为:“资源目录” ,功能清单如下,而此篇文章的功能描述在于“在线编目”里面实现中。业务和整体的实现逻辑就不多说了,挺多的!这里只是围绕具体的增加、删除行剖析即可。

--------功能列表--------

资源目录管理

资源目录管理-在线编目

资源目录管理-资源审核

资源目录管理-资源目录检索

资源目录共享

资源目录共享-资源申请

资源目录共享-资源审核

资源目录共享-资源获取

功能实现

实现的jsp代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<base target="_self">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/common/meta.jsp"/>
<link href="${ctx}/skins/blue/css/sjsjzx.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx }/tiles/scripts/jquery-1.8.0.min.js"></script>
<!-- 表单验证组件 -->
 <script type="text/javascript" src="${ctx}/tiles/Validform/js/Validform_v5.3.2.js"></script>
 <link rel="stylesheet" type="text/css" href="${ctx}/tiles/Validform/css/style.css"/>
<title>在线编目</title>
<style type="text/css">
.button{
	position: relative;
    overflow: visible;
    display: inline-block;
    padding: 0.5em 1em;
    border: 1px solid #6495ED;
    margin: 0;
    width:120px;
    text-decoration: none;
    text-shadow: 1px 1px 0 #fff;
    font-family:"Microsoft YaHei", "微软雅黑", "宋体", Arial, Helvetica, sans-serif;
	font-size: 16px;
    color: #333;
    font-weight:bold;
    white-space: nowrap;
    cursor: pointer;
    outline: none;
    background-color: #fff;
    -webkit-background-clip: padding;
    -moz-background-clip: padding;
    -o-background-clip: padding-box;
    /*background-clip: padding-box;*/ /* commented out due to Opera 11.10 bug */
    -webkit-border-radius: 0.2em;
    -moz-border-radius: 0.2em;
    border-radius: 0.2em;
    /* IE hacks */
    zoom: 1;
    *display: inline;
}
.dfinput{width:345px; height:25px; line-height:25px; border-top:solid 1px #a7b5bc; border-left:solid 1px #a7b5bc; border-right:solid 1px #ced9df; border-bottom:solid 1px #ced9df; background:url(../images/inputbg.gif) repeat-x; text-indent:10px;}
</style>
<script type="text/javascript">
function dosubmit(){
	if($('#resourceName').val()==''){
		alert("请输入资源目录名称!");
		return;
	}
	if($('#infoSysName').val()==''){
		alert("请输入信息系统名称!");
		return;
	}
	if($('#sysAbstract').val()==''){
		alert("请输入信息系统简介!");
		return;
	}
	if($('#provideDepartment').val()==''){
		alert("请输入提供科室!");
		return;
	}
	if($('#keyWord').val()==''){
		alert("请输入检索关键字!");
		return;
	}
	if($('#busLinkman').val()==''){
		alert("请输入业务联系人姓名!");
		return;
	}
	if($('#busLinkmanPhone').val()==''){
		alert("请输入业务联系人电话!");
		return;
	}
	if($('#jointLinkman').val()==''){
		alert("请输入对接联系人姓名!");
		return;
	}
	if($('#jointLinkmanPhone').val()==''){
		alert("请输入对接联系人电话!");
		return;
	}
	if($('#jointType').val()==''){
		alert("请输入对接方式!");
		return;
	}
	if($('#shareProperty').val()==''){
		alert("请选择共享属性!");
		return;
	}
	if($('#openProperty').val()==''){
		alert("请选择公开属性!");
		return;
	}
	if($('#updateRate').val()==''){
		alert("请输入更新频度!");
		return;
	}
	if($('#resourceType').val()==''){
		alert("请选择资源类型!");
		return;
	}
	//校验资源项信息
	$('#resourceList').find("input").each(function(){
		var thisId = $(this).attr("id");
		alert(thisId.val());
		if(thisId.val() == ""){
			alert("资源项属性不能为空!");
			return;
		}
	});

	if(confirm("确定要保存吗?")){
			$("#mainForm").submit();
	}
}
</script>
</head>
<body>
<p style="text-align:center;font-size:20px;padding-bottom: 15px;padding-top: 10px;"><b>在线编目</b></p>
<form id="mainForm" name="mainForm" action="${ctx }/zymlgl/saveBm" method="post" >
<input type="hidden" id="" name="resources.resourceId" value="${obj.resources.resourceId}">
<input type="hidden" id="" name="dept" value="${obj.dept}">
<table width="90%" class="table_multilist" align="center">
	<tr>
		<td width="15%" class="label_1">资源目录名称</td>
		<td width="85%" colspan="6" class="label_2">
		 <input type="text" class="dfinput" style="width:98%" id="resourceName" name="resources.resourceName" value="${obj.resources.resourceName}" datatype="*1-200" nullmsg="请输入url!" errormsg="请输入少于200个汉字!"/>
		</td >
	</tr>
	<tr>
		<td width="15%" class="label_1">摘要</td>
		<td width="85%" colspan="6" class="label_2">
		 <input type="text" class="dfinput" style="width:98%" id="abstractWord" name="resources.abstractWord" value="${obj.resources.abstractWord}" datatype="*1-200" nullmsg="请输入url!" errormsg="请输入少于200个汉字!"/>
		</td >
	</tr>
	<tr>
		<td width="15%" class="label_1">信息系统名称</td>
		<td width="85%" colspan="6" class="label_2">
		 <input type="text" class="dfinput" style="width:98%" id="infoSysName" name="resources.infoSysName" value="${obj.resources.infoSysName}" datatype="*1-200" nullmsg="请输入url!" errormsg="请输入少于200个汉字!"/>
		</td >
	</tr>
	<tr>
		<td width="15%" class="label_1">系统简介</td>
		<td width="85%" colspan="6" class="label_2">
		 <input type="text" class="dfinput" style="width:98%" id="sysAbstract" name="resources.sysAbstract" value="${obj.resources.sysAbstract}" datatype="*1-200" nullmsg="请输入url!" errormsg="请输入少于200个汉字!"/>
		</td >
	</tr>
	<tr>
		<td width="15%" class="label_1">信息系统链接</td>
		<td width="85%" colspan="6" class="label_2">
		 <input type="text" class="dfinput" style="width:98%" id="sysUrl" name="resources.sysUrl" value="${obj.resources.sysUrl}" datatype="*1-200" nullmsg="请输入url!" errormsg="请输入少于200个汉字!"/>
		</td >
	</tr>
	<tr>
		<td width="15%" class="label_1">检索关键字</td>
		<td width="85%" colspan="6" class="label_2">
		 <input type="text" class="dfinput" style="width:98%" id="keyWord" name="resources.keyWord" value="${obj.resources.keyWord}" datatype="*1-200" nullmsg="请输入url!" errormsg="请输入少于200个汉字!"/>
		</td >
	</tr>
	<tr>
		<td width="15%" class="label_1">提供科室</td>
		<td width="85%" colspan="6" class="label_2">
		 <input type="text" class="dfinput" style="width:98%" id="keyWord" name="resources.provideDepartment" value="${obj.resources.provideDepartment}" datatype="*1-200" nullmsg="请输入url!" errormsg="请输入少于200个汉字!"/>
		</td>
	</tr>
	<tr>
		<td class="label_1">业务联系人</td>
		<td width="35%" class="label_2" colspan="2">
		 <input type="text" class="dfinput" style="width:95%" id="busLinkman" name="resources.busLinkman" value="${obj.resources.busLinkman}" datatype="*1-50" nullmsg="请输入返回参数!" errormsg="请输入少于50个汉字!"/>
		</td>
		<td width="15%" class="label_1">联系电话</td>
		<td width="35%" class="label_2" colspan="3">
		 <input type="text" class="dfinput" style="width:95%" id="busLinkmanPhone" name="resources.busLinkmanPhone" value="${obj.resources.busLinkmanPhone}" datatype="*1-50" nullmsg="请输入返回参数!" errormsg="请输入少于50个汉字!"/>
		</td>
	</tr>
	<tr>
		<td class="label_1">对接联系人</td>
		<td width="35%" class="label_2" colspan="2">
		 <input type="text" class="dfinput" style="width:95%" id="jointLinkman" name="resources.jointLinkman" value="${obj.resources.jointLinkman}" datatype="*1-50" nullmsg="请输入返回参数!" errormsg="请输入少于50个汉字!"/>
		</td>
		<td width="15%" class="label_1">联系电话</td>
		<td width="35%" class="label_2" colspan="3">
		 <input type="text" class="dfinput" style="width:95%" id="jointLinkmanPhone" name="resources.jointLinkmanPhone" value="${obj.resources.jointLinkmanPhone}" datatype="*1-50" nullmsg="请输入返回参数!" errormsg="请输入少于50个汉字!"/>
		</td>
	</tr>
	<tr>
		<td class="label_1">对接方式</td>
		<td width="35%" class="label_2" colspan="2">
		 <wd:select name="resources.jointType" id="jointType" dicCode="1064" initValue="---请选择---" className="selectInput" style="width:175px;height:25px;" defaultValue="${obj.resources.jointType}"/>
		</td>
		<td width="15%" class="label_1">资源更新频度</td>
		<td width="35%" class="label_2" colspan="3">
		 <wd:select name="resources.updateRate" id="updateRate" dicCode="1063" initValue="---请选择---" className="selectInput" style="width:175px;height:25px;" defaultValue="${obj.resources.updateRate}"/>
		</td>
	</tr>
	<tr>
		<td class="label_1">资源共享属性</td>
		<td width="35%" class="label_2" colspan="2">
		 <wd:select name="resources.shareProperty" id="shareProperty" dicCode="1056" initValue="---请选择---" className="selectInput" style="width:175px;height:25px;" defaultValue="${obj.resources.shareProperty}"/>
		</td>
		<td width="15%" class="label_1">资源公开属性</td>
		<td width="35%" class="label_2" colspan="3">
		 <wd:select name="resources.openProperty" id="openProperty" dicCode="1057" initValue="---请选择---" className="selectInput" style="width:175px;height:25px;" defaultValue="${obj.resources.openProperty}"/>
		</td>
	</tr>
	<tr>
		<td class="label_1">所属资源类型</td>
		<td width="35%" class="label_2" colspan="2">
		 <wd:select name="resources.resourceType" id="resourceType" dicCode="1054" initValue="---请选择---" className="selectInput" style="width:175px;height:25px;" defaultValue="${obj.resources.resourceType}"/>
		</td>
		<td width="15%" class="label_1">数据库表名</td>
		<td width="35%" class="label_2" colspan="3">
		 <input type="text" class="dfinput" style="width:95%" id="tableName" name="resources.tableName" value="${obj.resources.tableName}" datatype="*1-50" nullmsg="请输入返回参数!" errormsg="请输入少于20个字符!"/>
		</td>
	</tr>
</table><br>
<!-- 资源项 -->
<table width="90%" class="table_multilist" align="center" id="maintable">
	<tr>
		<td class="label_1" width="12%" style="text-align: center;">资源项名称</td>
		<td class="label_1" width="12%" style="text-align: center;">数据库字段名</td>
		<td class="label_1" width="10%" style="text-align: center;">数据类型</td>
		<td class="label_1" width="15%" style="text-align: center;">备注</td>
		<td class="label_1" width="10%" style="text-align: center;">共享属性</td>
		<td class="label_1" width="15%" style="text-align: center;">不予共享理由</td>
		<td class="label_1" width="10%" style="text-align: center;">公开属性</td>
		<td class="label_1" width="15%" style="text-align: center;">不予公开理由</td>
		<td class="label_1" width="5%" align="left"><input type="button" value="+" onclick="addRow()"/></td>
	</tr>
	<!-- 克隆模板 -->
	<tr id="branchTr" style="display:none;">
			<td class="label_2" width="12%" style="text-align: center;">
				<input type="text" class="dfinput" style="width:90%" id="dataItemName_0" name="resourceDetailList[0].dataItemName" value="${resource.dataItemName}"/>
			</td>
			<td class="label_2" width="12%" style="text-align: center;">
				<input type="text" class="dfinput" style="width:90%" id="fieldCode_0" name="resourceDetailList[0].fieldCode" value="${resource.fieldCode}"/>
			</td>
			<td class="label_2" width="10%" style="text-align: center;">
				<wd:select name="resourceDetailList[0].dataItemType" id="dataItemType_0" dicCode="1055" initValue="--请选择--" className="selectInput" style="width:98%" defaultValue="${resource.dataItemType}"/>
			</td>
			<td class="label_2" width="15%" style="text-align: center;"><input type="text" class="dfinput" style="width:90%" id="memo" name="resourceDetailList[0].memo" value="${resource.memo}"/></td>
			<td class="label_2" width="12%" style="text-align: center;">
				<wd:select name="resourceDetailList[0].shareProperty" id="shareProperty_0" dicCode="1056" initValue="--请选择--" className="selectInput" style="width:98%" defaultValue="${resource.shareProperty}"/>
			</td>
			<td class="label_2" width="15%" style="text-align: center;">
				<input type="text" class="dfinput" style="width:90%" id="noShareReason_0" name="resourceDetailList[0].noShareReason" value="${resource.noShareReason}"/>
			</td>
			<td class="label_2" width="12%" style="text-align: center;">
				<wd:select name="resourceDetailList[0].openProperty" id="openProperty_0" dicCode="1057" initValue="--请选择--" className="selectInput" style="width:98%" defaultValue="${resource.openProperty}"/>
			</td>
			<td class="label_2" width="15%" style="text-align: center;">
				<input type="text" class="dfinput" style="width:90%" id="noOpenReason_0" name="resourceDetailList[0].noOpenReason" value="${resource.noOpenReason}"/>
			</td>
			<td class="label_2" width="5%" style="text-align: center;"><input type="button" value="删除" onclick="deleteRow(this)"/></td>
		</tr>
	<c:forEach items="${obj.resourceDetailList}" var="resource" varStatus="row">
		<tr>
			<td class="label_2" width="12%" style="text-align: center;">
				<input type="text" class="dfinput" style="width:90%" id="dataItemName_0" name="resourceDetailList[${row.index+1}].dataItemName" value="${resource.dataItemName}"/>
			</td>
			<td class="label_2" width="12%" style="text-align: center;">
				<input type="text" class="dfinput" style="width:90%" id="fieldCode_0" name="resourceDetailList[${row.index+1}].fieldCode" value="${resource.fieldCode}"/>
			</td>
			<td class="label_2" width="10%" style="text-align: center;">
				<wd:select name="resourceDetailList[${row.index+1}].dataItemType" id="dataItemType_0" dicCode="1055" initValue="---请选择---" className="selectInput" style="width:98%" defaultValue="${resource.dataItemType}"/>
			</td>
			<td class="label_2" width="15%" style="text-align: center;"><input type="text" class="dfinput" style="width:90%" id="memo_0" name="resourceDetailList[${row.index+1}].memo" value="${resource.memo}"/></td>
			<td class="label_2" width="12%" style="text-align: center;">
				<wd:select name="resourceDetailList[${row.index+1}].shareProperty" id="shareProperty_0" dicCode="1056" initValue="---请选择---" className="selectInput" style="width:98%" defaultValue="${resource.shareProperty}"/>
			</td>
			<td class="label_2" width="15%" style="text-align: center;">
				<input type="text" class="dfinput" style="width:90%" id="noShareReason_0" name="resourceDetailList[${row.index+1}].noShareReason" value="${resource.noShareReason}"/>
			</td>
			<td class="label_2" width="12%" style="text-align: center;">
				<wd:select name="resourceDetailList[${row.index+1}].openProperty" id="openProperty_0" dicCode="1057" initValue="---请选择---" className="selectInput" style="width:98%" defaultValue="${resource.openProperty}"/>
			</td>
			<td class="label_2" width="15%" style="text-align: center;">
				<input type="text" class="dfinput" style="width:90%" id="noOpenReason_0" name="resourceDetailList[${row.index+1}].noOpenReason" value="${resource.noOpenReason}"/>
			</td>
			<td class="label_2" width="5%" style="text-align: center;">
				<input type="hidden" name="resourceDetailList[${row.index+1}].detailsId" value="${resource.detailsId}"/>
				<input type="button" value="删除" onclick="deleteRow(this)"/>
			</td>
		</tr>
	</c:forEach>
</table>

<div style="text-align: center;margin-top: 20px;padding-bottom: 10px">
		<input type="button" id="button"  class="button" value="保存修改" onclick="dosubmit();" />
</div>
</form>

<script>
var index = ${fn:length(obj.resourceDetailList)};
function addRow(obj) {
	index++;
	var listName = "resourceDetailList[0]";
	var cloneTr = $("#branchTr").clone();
	$(cloneTr).show();
	$(cloneTr).attr("id",$("#branchTr").attr("id")+"_"+index);
	$(cloneTr).find("input").each(function(){
		var thisName = $(this).attr("name");
		var thisId = $(this).attr("id");
		if(thisName){
			if(thisName.indexOf(listName) != -1){
				$(this).attr("name",thisName.replace(listName,"resourceDetailList["+ index + "]"));
			}
		}
		if(thisId){
			$(this).attr("id",thisId.replace("_0","_"+index));
		}
	});
	$(cloneTr).find("select").each(function(){
		var thisName = $(this).attr("name");
		var thisId = $(this).attr("id");
		if(thisName){
			if(thisName.indexOf(listName) != -1){
				$(this).attr("name",thisName.replace(listName,"resourceDetailList["+ index + "]"));
			}
		}
		if(thisId){
			$(this).attr("id",thisId.replace("_0","_"+index));
		}
	});
	$(cloneTr).appendTo($("#maintable"));	

	}
    function deleteRow(obj) {
		if(confirm("确定删除吗?")){
			$(obj).parent().parent().remove();
		}
	}

</script>
</body>
</html>

增加行采用克隆方式,在后台接收值的方法如下:

public View saveBm(@Param("::resources") Resource resources, @Param("::resourceDetailList") List<ResourceDetails> resourceDetailList,String dept, HttpServletRequest request)

此接收方式的写法看着不一样吧,用惯了SSH或SSM框架感觉不一样,这里用的是Nutz框架;如果是SSH或SSM框架,接收时写个List<ResourceDetails>,然后get(),set()就可以了。

增加行、删除行效果如下:

编辑同样效果如下:

时间: 2024-08-06 01:52:59

js 克隆行、删除行的相关文章

Js 克隆

1.浅表克隆 调用concate() 或者slice() 方法,可以创建数组的浅表副本,在浅表副本中,如果原始数组的元素是复杂数据类型,则元素值指向对象的引用而非对象本身, 与原始数组一样,浅表副本的元素值也是指向对象引用,对对象所做的任何更改都会在两个数组中反映出来. 2.深度克隆 深度克隆是相对于浅表而言的,在克隆的深度副本中,不断复制索引,还将复制原始数组中的所有对象,从而使新数组和原始数组指向不同对象. 实现的一个方法: function cloneArray(_arry ,deep){

Node.js 命令行工具的编写

日常开发中,编写 Node.js 命令行工具来完成一些小任务是很常见的操作.其编写也不难,和日常编写 Node.js 代码并无二致. package.json 中的 bin 字段 一个 npm 模块,如果在 package.json 中指定了 bin 字段,那说明该模块提供了可在命令行执行的命令,这些命令就是在 bin 字段中指定的. package.json { "bin": { "myapp": "./cli.js" } } 程序安装后会可在

Visual Studio报错/plugin.vs.js,行:1074,错误:缺少标识符、字符串或数字

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PrivateAssemblies/plugin.vs.js 行:1074Char:13错误:缺少标识符.字符串或数字代码:0 解决方法: 选择 调试-> 选项 不选中"调试时启动诊断工具"[取消对勾] 点击确定. 取消对勾 原文地址:https://www.cnblogs.com/51net/p/12029944.html

Node.js 命令行程序开发教程

nodejs开发命令行程序非常方便,具体操作方式查看下面几篇文章 http://www.ruanyifeng.com/blog/2015/05/command-line-with-node.html 基于node构建命令行工具

js表格行上下移动

<script type="text/javascript"> function tagPosition() { $('#easyTables').tabs('select', '输出方式'); var rows = $('#dgTag').datagrid('getRows');//获取当前页的数据行 //var ary = new Array(); var ary = ""; for (var i = 0; i < rows.length; i

vue.js几行实现的简单的todo list

序:目前前端框架如:vue.react.angular,构建工具fis3.gulp.webpack等等...... 可谓是五花八门,层出不穷,眼花缭乱...其实吧只要你想玩还是可以玩玩的..下面是看了2天vuejs的官方文档实现了一个简单的todo list.感觉确实方便~!~ 预览戳这里 vuejs官方:http://cn.vuejs.org/ <!DOCTYPE html> <html lang="en"> <head> <meta cha

chrome console js多行输入

一直以来,Chrome控制台都缺少象IE调试台那样的多行执行模式.  今天意外发现Chrome其实也支持多行模式.默认在Chrome控制台上输入回车后会执行该命令,只需要通过输入Shift+Enter来新建行即可. 

js多行字符串

最基本的做法是: js 代码 var str = "111\n222\n333"; 但是这样不好排版.JavaScript 本身支持“\”的断句方式,于是可以这样写: js 代码 var str = "111\n\ 222\n\ 333"; 但是还是不爽,平白无故加上了一个反斜杠.有人提出利用 XML 结构来实现,但是具有语法高亮的编辑器通常会被这种写法弄糊涂. 高人无处不在,有人竟然利用注释.个人觉得这是最方便的了.我将其改了一下: js 代码 Function.

JS克隆DIV并删除DIV(插入删除按钮)

<div id="div"> <select id="stu" name="stuff_type"> <#list stuffType as st> <option value="${st.dict_code}"> ${(st.dict_name)!}</option> </#list> </select> 数量: <input name