在js里获取动态的id,形如$("#动态id")

转自https://blog.csdn.net/qq_23145857/article/details/51498973

js:

/*验证  preplay  页面表单*/
$().ready(


function() {

$("#listTable").find("tr").hover(function() {
$("#delete_id").val($(this).children("td").eq(0).html());
$("#delete_title").val($(this).children("td").eq(1).text());


})

// 日期控件
$(".Wdate").focus(function() {
WdatePicker({
skin : 'whyGreen',
dateFmt : 'yyyy-MM-dd',
readOnly : true,
onpicked : function() {
// cancel();
}
});
});
})




function hidenDiv(){

if ($("#content").css("display") == "none") {
$("#content").show();
$("#htmlContent").text(content)
} else {
$("#content").hide();
}



}






function validate(form) {
var id = $(form).attr("id");
var prefix = id.substring(0, id.indexOf('_') + 1);
var title = $("#" + prefix + "title").val();
var module = $("#" + prefix + "module").val();
var content = $("#" + prefix + "content").val();




if (title == "") {
inlineMsg(prefix + "title", '文章標題不能为空.', 2);
return false;
}
if (module == "") {
inlineMsg(prefix + "module", '所属模块不能为空.', 2);
return false;
}
if (content == "") {
inlineMsg(prefix + "content", '内容不能为空.', 2);
return false;
}

return true;
}


function titles(Obj){
var k=Obj;
var qian="add_";
var ids=qian+k;
var ids2='#'+ids;
var ids3='"'+ids2+'"';
$("#adds_"+k+"").attr("style","display:show();");//这个动态的k作用很大,很多地方都需要
}

function fanhui(){
$("#maintable").attr("style","display:show();");
$("#queryForm").attr("style","display:show();");
$("#main").attr("style","display:show();");
$(".adds").attr("style","display:none;");//通过class控制全部相同前缀id的div隐藏或显示
}

jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>


<script src="./scripts/util/Validate.js"></script>
<script src="./scripts/defence/workNews.js"></script>




<input type="hidden" id="tips" value="${param.tips}" />


<c:if test="${param.flag==true}">
<script type="text/javascript">
layer.msg(decodeURI($("#tips").val()), 2, 1);
layer.shift('top', 500);
</script>
</c:if>
<c:if test="${param.flag==false}">
<script type="text/javascript">
layer.msg(decodeURI($("#tips").val()), 2, 5);
layer.shift('top', 500);
</script>
</c:if>






<table style="width: 60%; height: 700px">
<tr
style="width: 100%; height: 18px; color: #000; padding-left: 10px; padding-bottom: 10px;">
当前位置:三防业务->业务辅助->三防工作动态</tr>

<tr>
<td style="width: 100%; height: 10%;">
<form action="workNews.do" method="post" id="queryForm">
<table style="width: 98%; color: #000; margin-left: 10px;">
<tr>


<td align="left" style="width: 10%"><c:forEach
items="${operate}" var="oper">
<c:if test="${oper.operateType=='ADD'}">
<div class="btn add_btn" model="add" title="添加三防工作动态" />
</c:if>
</c:forEach></td>
</tr>
</table>
</form>
</td>
</tr>


<tr>
<td style="width: 40%; height: 85%;">


<div id="main"
style="width: 98.5%; height: 100%; background: #ffffff; overflow: auto; text-align: center; display: ture;">


<table style="width: 100%;" id="listTable">
<thead>
<tr>
<th style="display: none;">ID</th>
<th align="left">标题</th>
<th>时间</th>
<th width="150px">操作</th>
</tr>
</thead>
<tbody>
<c:forEach items="${workNewsList}" var="item">
<tr>
<td style="display: none;">${item.id}</td>
<td style="display: none;">${item.title}</td>
<td align="left">
<a onclick="javascript:titles(${item.id}); return false;" href="#">${item.title}</a>
</td>
<td>${item.createTime}</td>
<td align="center">
<div style="width: 120px;">
<c:forEach items="${operate}" var="oper">
<c:if test="${oper.operateType=='EDIT'}">
<div class="btn edit_btn" style="float: left;" model="edit"
title="修 改"></div>
</c:if>
<c:if test="${oper.operateType=='DELETE'}">
<div class="btn del_btn" style="float: right" model="delete"
title="删 除"></div>
</c:if>
</c:forEach>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</td>
<td></td>
</tr>
</table>


<!-- 添加 -->
<div id="add" class="dialog" style="display: none;">
<form action="addWorkNews.do" method="post"
onsubmit="return validate(this)" id="add_form">
<table style="border-spacing: 15px">
<tr>
<td>标题</td>
<td><input type="text" id="add_title" name="add_title"
style="width: 100%" /></td>
<td>所属模块</td>
<td><input type="text" id="add_module" name="add_module"
style="width: 100%" /></td>
<td>时间</td>
<td><input type="text" id="add_createTime" name="add_createTime"
style="width: 100%" /></td>
</tr>
<tr>
<td>内容</td>
<td colspan="5"><textarea id="add_content" name="add_content"
style=" width: 100%; height: 100%;" cols="70" rows="10"></textarea></td>
</tr>


<tr>
<td colspan="4" align="center">
<div style="width: 150px;">
<div class="btn save_btn" onclick="submit_form('add_form')"
style="float: left;'"></div>
<div class="btn close_btn" model-close="add"
style="float: right;'"></div>
</div>
</td>
</tr>
</table>
</form>
</div>


<!-- 删除 -->
<div id="delete" class="dialog" style="display: none;">
<form action="deleteWorkNews.do" method="post" id="delete_form">
<table style="border-spacing: 15px">
<tr style="display: none;">
<td>ID</td>
<td><input type="text" readonly id="delete_id" name="delete_id" /></td>
</tr>
<tr>
<td>标题</td>
<td><input type="text" readonly id="delete_title"
name="delete_title" /></td>
</tr>
<tr>
<td colspan="4" align="center">
<div style="width: 150px;">
<div class="btn del_btn" onclick="submit_form('delete_form')"
style="float: left;"></div>
<div class="btn close_btn" model-close="delete"
style="float: right;"></div>
</div>
</td>
</tr>
</table>
</form>
</div>


<c:forEach items="${workNewsList}" var="item">
<div id="adds_${item.id}"  class="adds" style="width:98.5%;height:100%; background: #ffffff; overflow: auto; text-align: center;display:none;">
<form action="editReservoir.do" method="post"  id="add_form_${item.id}">


<table style="width: 100%;" id="listTable">
<thead>
<tr>
<th style="display: none;">ID</th>
<th align="left">标题111</th>
<th>时间111</th>
<th width="150px">操作111</th>
</tr>
</thead>
<tbody>
<tr>
<td style="display: none;">${item.id}</td>
<td style="display: none;">${item.title}</td>
<td align="left">
<a href="news.do?method=News&newsid=${item.id}" >${item.title}</a>
</td>
<td>${item.createTime}</td>
<td align="center">
<div style="width: 120px;">
<c:forEach items="${operate}" var="oper">
<c:if test="${oper.operateType=='EDIT'}">
<div class="btn edit_btn" style="float: left;" model="edit"
title="修 改"></div>
</c:if>
<c:if test="${oper.operateType=='DELETE'}">
<div class="btn del_btn" style="float: right" model="delete"
title="删 除"></div>
</c:if>
</c:forEach>
</div>
</td>
</tr>

</tbody>
</table>
</div>
</c:forEach>

猜你喜欢

转载自blog.csdn.net/weixin_42253152/article/details/81237714