layer页面跳转,获取html子节点元素的值方法

前端之家收集整理的这篇文章主要介绍了layer页面跳转,获取html子节点元素的值方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、jsp页面,携带值跳转到新页 original.jsp

  1. var btnClick = {'click .shownewPage':function (e,value,row,index) {//点击按钮时触发时间
  2. var Id = row.Id;
  3.  
  4. layer.open({
  5. title: '跳转到新页',type: 2,content: '/switch/switchAction!getNewPage.do?Id='+Id,//struts配置文件指定的跳转路径
  6. area: ['970px','610px'],shadeClose: true //点击遮罩关闭
  7. });
  8.  
  9. }};

2、后台跳转类 SwitchAction.java

  1. @Scope(value = "prototype")
  2. @Controller("SwitchAction ")
  3. public class SwitchAction implements ServletRequestAware,ServletResponseAware,ModelDriven{
  4. protected HttpServletRequest request;
  5. protected HttpServletResponse response;
  6.  
  7. public String getNewPage(){
  8. String Id = request.getParameter("Id"); //获取传递的参数
  9. request.setAttribute("Id",Id); //设置属性值,传递参数
  10. return "newPage"; //struts配置文件跳转新页指定返回字符串
  11. }
  12.  
  13. public String getnewHtml(){
  14. JSONObject json = new JSONObject();
  15. String Id = request.getParameter("Id");
  16. PageRecord pageRecord = pageService.getObjectById(Id); //根据Id获取内容
  17. StringBuffer newHtml= new StringBuffer(pageRecord .getnewHtml);//得到表中String类型的html字符串
  18. try {
  19. response.getWriter().print(newHtml.toString()); //将html的字符串输出页面
  20. } catch (IOException e) {
  21. json.put("success",false);
  22. e.printStackTrace();
  23. }
  24. return null;
  25. }
  26. }

3、struts配置文件,根据返回字符串跳转到新页

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  4. "http://struts.apache.org/dtds/struts-2.0.dtd">
  5.  
  6. <struts>
  7. <package name="switch" namespace="/switch" extends="bob-default">
  8. <action name="switchAction" class="SwitchAction">
  9. <result name="newPage">/WEB-INF/jsp/switch/newPage.jsp</result>
  10. </action>
  11. </package>
  12. </struts>

4、将需要填充的html字符串填充到新页的表格(newPage.jsp)

  1. var Id = '${Id}';
  2. $(document).ready(function(){
  3. //将html字符串填充到表格
  4. $.ajax({
  5. type:"post",url:"/switch/SwitchAction!getNewHtml.do",data: {
  6. "Id":Id
  7. },success:function(data){
  8. $("#hiddenTable").html(data);//将html字符串转化为jquery对象
  9. var basichtml = $("#hiddenTable").find('#id-body').html();//查找对象中子节点的值,即表格内容
  10. var str = "<tr><th width=\"5%\">序号</th><th width=\"7%\">属性名</th><th width=\"17%\">变更前</th><th width=\"17%\">变更后</th></tr>";
  11. var basichtml = str + basichtml;//加上表头
  12. $("#basicTable").html(basichtml)//将拼接的新字符串填充到表格
  13. refreshTabOffset();//刷新body页面
  14. },error:function(data){
  15. var str = data.html;
  16. alert("加载失败。");
  17. refreshTabOffset();
  18. }
  19. });
  20. });

5、newHtml

  1. StringBuffer newPage = new StringBuffer();
  2.  
  3. newPage.append"<thead><tr><th width=\"5%\">序号</th><th width=\"7%\">属性名</th><th width=\"17%\">变更前</th><th width=\"17%\">变更后</th></tr></thead>");
  4.  
  5. newPage.append"<tbody id=\"id-body\">");
  6. resNo = resNo + 1;
  7. newPage.append("<tr><td>"+ resNo + "</td><td>编码</td>" + "<td>" + origCode + "</td>" + "<td>" + newCode + "</td></tr></tbody>");

6、PageServiceImpl.java

  1. @Scope("singleton")
  2. @Service("PageService")//自动装载
  3. public class PageServiceImpl implements PageService{
  4. @Autowired //自动装载
  5. PageDao pageDao;
  6.  
  7. @Override
  8. public PageRecord getObjectById(String Id) {
  9. return pageDao.getObjectById(Id);
  10. }

7、PageDaoImpl.java

  1. @Scope("singleton")
  2. @Repository("PageDao")//自动装载
  3. public class PageDaoImpl extends HibernateGenericDao implements PageDao{
  4.  
  5. @Override
  6. public PageRecord PageRecord(PageRecord record) {
  7. if (record != null) {
  8. this.saveOrUpdate(record);
  9. }
  10. return record;
  11. }
  12.  
  13. @Override
  14. public PageRecord getObjectById(String Id) {
  15. PageRecord PageRecord = null;
  16. if(StringUtil.isEmpty(Id))
  17. return null;
  18. StringBuffer hql = new StringBuffer( "from PageRecord where Id=:Id ");//防止sql注入
  19. Map<String,Object> map = new HashMap<String,Object>();//防止sql注入
  20. map.put("Id",Integer.parseInt(Id)); //防止sql注入
  21. List<PageRecord> list = this.getListByHql(hql.toString(),map);
  22. if(list.size()>0){
  23. PageRecord = list.get(0);
  24. }
  25. return PageRecord;
  26. }

8、jsp页面引用插件

  1. <!-- jQuery -->
  2. <script src="/bower_components/jquery/dist/jquery.min.js"></script>
  3.  
  4. <!-- Bootstrap Core JavaScript -->
  5. <script src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
  6.  
  7. <!-- Metis Menu Plugin JavaScript -->
  8. <script src="/bower_components/metisMenu/dist/metisMenu.min.js"></script>
  9.  
  10. <!-- Custom Theme JavaScript -->
  11. <script src="/dist/js/sb-admin-2.js"></script>
  12.  
  13. <!-- Layer Popover JavaScript -->
  14. <script src="/UIReference/layer/layer.js"></script>
  15.  
  16. <!-- DateTimePicker JavaScript -->
  17. <script
  18. src="/UIReference/DatetimePicker/js/bootstrap-datetimepicker.min.js"></script>
  19. <script
  20. src="/UIReference/DatetimePicker/js/locales/bootstrap-datetimepicker.zh-CN.js"
  21. charset="UTF-8"></script>
  22.  
  23. <script src="/lib/jquery-validation/jquery.validate.js"></script>
  24. <script src="/UIReference/echarts3/echarts.min.js"></script>
  25. <script type="text/javascript">//自定义脚本</script>

9、jsp页面引用CSS

  1. <!-- Bootstrap Core CSS -->
  2. <link href="/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="external nofollow"
  3. rel="stylesheet">
  4.  
  5. <!-- MetisMenu CSS -->
  6. <link href="/bower_components/metisMenu/dist/metisMenu.min.css" rel="external nofollow"
  7. rel="stylesheet">
  8.  
  9. <!-- Timeline CSS -->
  10. <link href="/dist/css/timeline.css" rel="external nofollow" rel="stylesheet">
  11. <link
  12. href="/UIReference/DatetimePicker/css/bootstrap-datetimepicker.min.css" rel="external nofollow"
  13. rel="stylesheet">
  14. <!-- Custom CSS -->
  15. <link href="/dist/css/sb-admin-2.css" rel="external nofollow" rel="stylesheet">
  16.  
  17. <!-- Custom Fonts -->
  18. <link href="/bower_components/font-awesome/css/font-awesome.min.css" rel="external nofollow"
  19. rel="stylesheet" type="text/css">
  20.  
  21. <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  22. <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  23. <!--[if lt IE 9]>
  24. <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  25. <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  26. <![endif]-->
  27. <style type="text/css"><!-- 自定义css--></style>

10、jsp页面布局

  1. <body οnlοad="refreshTabOffset()">
  2. <div class="container-fluid">
  3. <div class="row">
  4. <div class="col-sm-12 add-bottom-line" role="navigation" id="infoNav">
  5. <!--<ul id="transverse-tab" class="nav nav-tabs" role="tablist">
  6.  
  7. <li id="tab-basicInfo" role="presentation" class = "active"
  8. οnclick="javascript:document.getElementById('basicInfo').scrollIntoView();switch(this,'0');"><a>基本信息</a></li>
  9. <li id="tab-Property" role="presentation"
  10. οnclick="javascript:document.getElementById('Property').scrollIntoView();switch(this,'1');"><a>属性</a></li>
  11. <li id="tab-RelationInfo" role="presentation"
  12. οnclick="javascript:document.getElementById('RelationInfo').scrollIntoView();switch(this,'2');"><a>关系</a></li>
  13. </ul>-->
  14. </div>
  15.  
  16. <div class="col-sm-12"
  17. style="height: 500px; overflow-y: scroll; position: relative;"
  18. id="myModalBodyPage" οnscrοll="singleScroll();">
  19.  
  20. <div class="row">
  21. <div class="panel panel-info hidden" id="switchLog">
  22. <table class="table table-hover table-striped table-bordered hidden"
  23. id="hiddenTable">
  24. <thead>
  25. <tr>
  26. <th width="5%">序号</th>
  27. <th width="7%">属性</th>
  28. <th width="17%">变更前</th>
  29. <th width="10%">变更后</th>
  30. </tr>
  31. </thead>
  32. </table>
  33. </div>
  34. <div class="panel panel-info" id="basicInfo">
  35. <div class="panel-heading">基本信息</div>
  36. <table class="table table-hover table-striped table-bordered"
  37. id="basicTable">
  38. </table>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </body>

以上这篇layer页面跳转,获取html子节点元素的值方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

猜你在找的JavaScript相关文章