layer頁(yè)面跳轉(zhuǎn),獲取html子節(jié)點(diǎn)元素的值方法
1、jsp頁(yè)面,攜帶值跳轉(zhuǎn)到新頁(yè) original.jsp
var btnClick = {'click .shownewPage':function (e, value, row, index) {//點(diǎn)擊按鈕時(shí)觸發(fā)時(shí)間
var Id = row.Id;
layer.open({
title: '跳轉(zhuǎn)到新頁(yè)',
type: 2,
content: '/switch/switchAction!getNewPage.do?Id='+Id, //struts配置文件指定的跳轉(zhuǎn)路徑
area: ['970px', '610px'],
shadeClose: true //點(diǎn)擊遮罩關(guān)閉
});
}};
2、后臺(tái)跳轉(zhuǎn)類(lèi) SwitchAction.java
@Scope(value = "prototype")
@Controller("SwitchAction ")
public class SwitchAction implements ServletRequestAware, ServletResponseAware, ModelDriven{
protected HttpServletRequest request;
protected HttpServletResponse response;
public String getNewPage(){
String Id = request.getParameter("Id"); //獲取傳遞的參數(shù)
request.setAttribute("Id", Id); //設(shè)置屬性值,傳遞參數(shù)
return "newPage"; //struts配置文件中跳轉(zhuǎn)新頁(yè)指定返回字符串
}
public String getnewHtml(){
JSONObject json = new JSONObject();
String Id = request.getParameter("Id");
PageRecord pageRecord = pageService.getObjectById(Id); //根據(jù)Id獲取表內(nèi)容
StringBuffer newHtml= new StringBuffer(pageRecord .getnewHtml);//得到表中String類(lèi)型的html字符串
try {
response.getWriter().print(newHtml.toString()); //將html的字符串輸出到頁(yè)面
} catch (IOException e) {
json.put("success", false);
e.printStackTrace();
}
return null;
}
}
3、struts配置文件,根據(jù)返回字符串跳轉(zhuǎn)到新頁(yè)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="switch" namespace="/switch" extends="bob-default">
<action name="switchAction" class="SwitchAction">
<result name="newPage">/WEB-INF/jsp/switch/newPage.jsp</result>
</action>
</package>
</struts>
4、將需要填充的html字符串填充到新頁(yè)的表格(newPage.jsp)
var Id = '${Id}';
$(document).ready(function(){
//將html字符串填充到表格
$.ajax({
type:"post",
url:"/switch/SwitchAction!getNewHtml.do",
data: {
"Id":Id
},
success:function(data){
$("#hiddenTable").html(data);//將html字符串轉(zhuǎn)化為jquery對(duì)象
var basichtml = $("#hiddenTable").find('#id-body').html();//查找對(duì)象中子節(jié)點(diǎn)的值,即表格內(nèi)容
var str = "<tr><th width=\"5%\">序號(hào)</th><th width=\"7%\">屬性名</th><th width=\"17%\">變更前</th><th width=\"17%\">變更后</th></tr>";
var basichtml = str + basichtml;//加上表頭
$("#basicTable").html(basichtml)//將拼接的新字符串填充到表格
refreshTabOffset();//刷新body頁(yè)面
},
error:function(data){
var str = data.html;
alert("加載失敗。");
refreshTabOffset();
}
});
});
5、newHtml
StringBuffer newPage = new StringBuffer();
newPage.append("<thead><tr><th width=\"5%\">序號(hào)</th><th width=\"7%\">屬性名</th><th width=\"17%\">變更前</th><th width=\"17%\">變更后</th></tr></thead>");
newPage.append("<tbody id=\"id-body\">");
resNo = resNo + 1;
newPage.append("<tr><td>"+ resNo + "</td><td>編碼</td>" + "<td>" + origCode + "</td>" + "<td>" + newCode + "</td></tr></tbody>");
6、PageServiceImpl.java
@Scope("singleton")
@Service("PageService")//自動(dòng)裝載
public class PageServiceImpl implements PageService{
@Autowired //自動(dòng)裝載
PageDao pageDao;
@Override
public PageRecord getObjectById(String Id) {
return pageDao.getObjectById(Id);
}
7、PageDaoImpl.java
@Scope("singleton")
@Repository("PageDao")//自動(dòng)裝載
public class PageDaoImpl extends HibernateGenericDao implements PageDao{
@Override
public PageRecord PageRecord(PageRecord record) {
if (record != null) {
this.saveOrUpdate(record);
}
return record;
}
@Override
public PageRecord getObjectById(String Id) {
PageRecord PageRecord = null;
if(StringUtil.isEmpty(Id))
return null;
StringBuffer hql = new StringBuffer( "from PageRecord where Id=:Id ");//防止sql注入
Map<String, Object> map = new HashMap<String, Object>();//防止sql注入
map.put("Id", Integer.parseInt(Id)); //防止sql注入
List<PageRecord> list = this.getListByHql(hql.toString(), map);
if(list.size()>0){
PageRecord = list.get(0);
}
return PageRecord;
}
8、jsp頁(yè)面引用插件
<!-- jQuery --> <script src="/bower_components/jquery/dist/jquery.min.js"></script> <!-- Bootstrap Core JavaScript --> <script src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script> <!-- Metis Menu Plugin JavaScript --> <script src="/bower_components/metisMenu/dist/metisMenu.min.js"></script> <!-- Custom Theme JavaScript --> <script src="/dist/js/sb-admin-2.js"></script> <!-- Layer Popover JavaScript --> <script src="/UIReference/layer/layer.js"></script> <!-- DateTimePicker JavaScript --> <script src="/UIReference/DatetimePicker/js/bootstrap-datetimepicker.min.js"></script> <script src="/UIReference/DatetimePicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script> <script src="/lib/jquery-validation/jquery.validate.js"></script> <script src="/UIReference/echarts3/echarts.min.js"></script> <script type="text/javascript">//自定義腳本</script>
9、jsp頁(yè)面引用CSS
<!-- Bootstrap Core CSS -->
<link href="/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="external nofollow"
rel="stylesheet">
<!-- MetisMenu CSS -->
<link href="/bower_components/metisMenu/dist/metisMenu.min.css" rel="external nofollow"
rel="stylesheet">
<!-- Timeline CSS -->
<link href="/dist/css/timeline.css" rel="external nofollow" rel="stylesheet">
<link
href="/UIReference/DatetimePicker/css/bootstrap-datetimepicker.min.css" rel="external nofollow"
rel="stylesheet">
<!-- Custom CSS -->
<link href="/dist/css/sb-admin-2.css" rel="external nofollow" rel="stylesheet">
<!-- Custom Fonts -->
<link href="/bower_components/font-awesome/css/font-awesome.min.css" rel="external nofollow"
rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<style type="text/css"><!-- 自定義CSS--></style>
10、jsp頁(yè)面布局
<body οnlοad="refreshTabOffset()">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12 add-bottom-line" role="navigation" id="infoNav">
<!--<ul id="transverse-tab" class="nav nav-tabs" role="tablist">
<li id="tab-basicInfo" role="presentation" class = "active"
οnclick="javascript:document.getElementById('basicInfo').scrollIntoView();switch(this,'0');"><a>基本信息</a></li>
<li id="tab-Property" role="presentation"
οnclick="javascript:document.getElementById('Property').scrollIntoView();switch(this,'1');"><a>屬性</a></li>
<li id="tab-RelationInfo" role="presentation"
οnclick="javascript:document.getElementById('RelationInfo').scrollIntoView();switch(this,'2');"><a>關(guān)系</a></li>
</ul>-->
</div>
<div class="col-sm-12"
style="height: 500px; overflow-y: scroll; position: relative;"
id="myModalBodyPage" οnscrοll="singleScroll();">
<div class="row">
<div class="panel panel-info hidden" id="switchLog">
<table class="table table-hover table-striped table-bordered hidden"
id="hiddenTable">
<thead>
<tr>
<th width="5%">序號(hào)</th>
<th width="7%">屬性名</th>
<th width="17%">變更前</th>
<th width="10%">變更后</th>
</tr>
</thead>
</table>
</div>
<div class="panel panel-info" id="basicInfo">
<div class="panel-heading">基本信息</div>
<table class="table table-hover table-striped table-bordered"
id="basicTable">
</table>
</div>
</div>
</div>
</div>
</div>
</body>
以上這篇layer頁(yè)面跳轉(zhuǎn),獲取html子節(jié)點(diǎn)元素的值方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Bootstrap table簡(jiǎn)單使用總結(jié)
這篇文章主要為大家總結(jié)了Bootstrap table的簡(jiǎn)單使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
基于layPage插件實(shí)現(xiàn)兩種分頁(yè)方式淺析
這篇文章主要為大家詳細(xì)介紹了基于layPage插件實(shí)現(xiàn)兩種分頁(yè)方式 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07
js 將圖片連接轉(zhuǎn)換成base64格式的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇js 將圖片連接轉(zhuǎn)換成base64格式的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08
js+canvas實(shí)現(xiàn)兩張圖片合并成一張圖片的方法
這篇文章主要介紹了js+canvas實(shí)現(xiàn)兩張圖片合并成一張圖片的方法,結(jié)合實(shí)例形式分析了JavaScript結(jié)合HTML5 canvas實(shí)現(xiàn)圖片合并的操作技巧,并附帶了Java圖片合并的實(shí)現(xiàn)方法,需要的朋友可以參考下2019-11-11
javascript實(shí)現(xiàn)移動(dòng)端 HTML5 圖片上傳預(yù)覽和壓縮功能示例
這篇文章主要介紹了javascript實(shí)現(xiàn)移動(dòng)端 HTML5 圖片上傳預(yù)覽和壓縮功能,結(jié)合實(shí)例形式分析了javascript移動(dòng)端 HTML5 圖片上傳預(yù)覽和壓縮功能具體實(shí)現(xiàn)方法與操作注意事項(xiàng),需要的朋友可以參考下2020-05-05
淺談js for循環(huán)輸出i為同一值的問(wèn)題
下面小編就為大家?guī)?lái)一篇淺談js for循環(huán)輸出i為同一值的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-03-03

