Home > Web Front-end > HTML Tutorial > Please help me solve the problem of using JS to append css elements (div or span) to the page_html/css_WEB-ITnose

Please help me solve the problem of using JS to append css elements (div or span) to the page_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:06:41
Original
1603 people have browsed it




Use CSS code to generate Table Fixed header


www.865171.cn





//You need to use JS to append









< /thead>



;td>Cell 5














< /tr>




  


  
  
  
  
  


  
  
  
  
  


  
  
  
  
  

h1 h2 h3 h4 h5


a< ;/td>
Cell 2 Cell 3


b
Cell 2 Cell 3 Cell 4 Cell 5


c
Cell 2 Cell 3 Cell 4 Cell 5


d< ;/td>
Cell 2 Cell 3 Cell 4 单元格5


e
单元格2 单元格3 单元格4 单元格5


f
单元格2 单元格3 单元格4 单元格5


g
单元格2 单元格3 单元格4 单元格5


<script> <br> //document.all.myt.insertAdjacentHTML("afterBegin","<h1>Insert content in the container before the text</h1>"); <br> // document.all.myt.insertAdjacentHTML("beforeEnd","<h2>Insert content in the container after the text</h2>"); <br> //document.all.myt.insertAdjacentHTML("beforeBegin"," <h2>Insert content in the container after the text</h2>"); <br> //document.all.myt.insertAdjacentHTML("beforeBegin","<div id='scrollDiv' class='scrollDiv' >"); <br> <br> </script>



?????????????????????????????????????????????
Just a simple fixed header page. I want to add a DIV or SPAN tag in front of the table and implement it later with JS (annotated below because it cannot achieve the effect I want). I have been looking for it for a long time but I can't find a solution. Does anyone know how to solve it?

The effect I want is that in the code of the page posted above, there is no DIV before the table tag. It needs to be appended in the subsequent JS, and then the effect of fixing the table header can also be achieved. I am pure CSS, JS novice, I hope someone can help me solve it!


Reply to discussion (solution)

Use jquery’s warp method to outsource a div, as follows

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css"> <!-- body,table, td, a {font:9pt;} /*重点:固定行头样式*/.scrollRowThead{position: relative; left: expression(this.parentElement.parentElement.parentElement.parentElement.scrollLeft);z-index:0;}/*重点:固定表头样式*//*行列交叉的地方*/.scrollCR { z-index:3;}/*div外框*/.scrollDiv {height:200px;clear: both; border: 1px solid #EEEEEE;OVERFLOW: scroll;width: 300px; }/*行头居中*/.scrollColThead td,.scrollColThead th{ text-align: center ;}/*行头列头背景*/.scrollRowThead,.scrollColThead td,.scrollColThead th{background-color:#FFFFFF;}/*表格的线*/.scrolltable{border-bottom:1px solid #CCCCCC; border-right:1px solid #CCCCCC; }/*单元格的线等*/.scrolltable td,.scrollTable th{border-left: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; padding: 5px; }thead tr{position: relative;top: expression(this.parentElement.parentElement.parentElement.scrollTop);z-index:3;background-color:#CCCCCC;}--> </style><script src="http://code.jquery.com/jquery-1.11.0.min.js"></script><script>$(function(){	$('#myt').wrap("<div id='scrollDiv' class='scrollDiv' >");})</script></head><body><h1>利用CSS代码让Table产生固定表头</h1><h3>www.865171.cn</h3><table><tr><td><table id="myt" border="0" cellpadding="3" cellspacing="0" width="300" class="scrollTable">    <thead >    <tr >      <th >h1</th>      <th >h2</th>      <th >h3</th>      <th >h4</th>      <th >h5</th>    </tr>    </thead>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox" value="checkbox">    a</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox2" value="checkbox">    b</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td nowrap class="scrollRowThead"  >    <input type="checkbox" name="checkbox3" value="checkbox">    c</td>      <td nowrap>单元格2</td>      <td nowrap>单元格3</td>      <td nowrap>单元格4</td>      <td nowrap>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox4" value="checkbox">    d</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox5" value="checkbox">    e</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox6" value="checkbox">    f</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead" >    <input type="checkbox" name="checkbox7" value="checkbox">    g</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    </table>	</td>    </tr></table></body><script>//document.all.myt.insertAdjacentHTML("afterBegin","<h1>在文本前容器内插入内容</h1>");//document.all.myt.insertAdjacentHTML("beforeEnd","<h2>在文本后容器内插入内容</h2>");//document.all.myt.insertAdjacentHTML("beforeBegin","<h2>在文本后容器内插入内容</h2>");//document.all.myt.insertAdjacentHTML("beforeBegin","<div id='scrollDiv' class='scrollDiv' >");</script></html>
Copy after login
Copy after login

Use jquery’s warp method to outsource a div, as follows

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css"> <!-- body,table, td, a {font:9pt;} /*重点:固定行头样式*/.scrollRowThead{position: relative; left: expression(this.parentElement.parentElement.parentElement.parentElement.scrollLeft);z-index:0;}/*重点:固定表头样式*//*行列交叉的地方*/.scrollCR { z-index:3;}/*div外框*/.scrollDiv {height:200px;clear: both; border: 1px solid #EEEEEE;OVERFLOW: scroll;width: 300px; }/*行头居中*/.scrollColThead td,.scrollColThead th{ text-align: center ;}/*行头列头背景*/.scrollRowThead,.scrollColThead td,.scrollColThead th{background-color:#FFFFFF;}/*表格的线*/.scrolltable{border-bottom:1px solid #CCCCCC; border-right:1px solid #CCCCCC; }/*单元格的线等*/.scrolltable td,.scrollTable th{border-left: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; padding: 5px; }thead tr{position: relative;top: expression(this.parentElement.parentElement.parentElement.scrollTop);z-index:3;background-color:#CCCCCC;}--> </style><script src="http://code.jquery.com/jquery-1.11.0.min.js"></script><script>$(function(){	$('#myt').wrap("<div id='scrollDiv' class='scrollDiv' >");})</script></head><body><h1>利用CSS代码让Table产生固定表头</h1><h3>www.865171.cn</h3><table><tr><td><table id="myt" border="0" cellpadding="3" cellspacing="0" width="300" class="scrollTable">    <thead >    <tr >      <th >h1</th>      <th >h2</th>      <th >h3</th>      <th >h4</th>      <th >h5</th>    </tr>    </thead>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox" value="checkbox">    a</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox2" value="checkbox">    b</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td nowrap class="scrollRowThead"  >    <input type="checkbox" name="checkbox3" value="checkbox">    c</td>      <td nowrap>单元格2</td>      <td nowrap>单元格3</td>      <td nowrap>单元格4</td>      <td nowrap>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox4" value="checkbox">    d</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox5" value="checkbox">    e</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox6" value="checkbox">    f</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead" >    <input type="checkbox" name="checkbox7" value="checkbox">    g</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    </table>	</td>    </tr></table></body><script>//document.all.myt.insertAdjacentHTML("afterBegin","<h1>在文本前容器内插入内容</h1>");//document.all.myt.insertAdjacentHTML("beforeEnd","<h2>在文本后容器内插入内容</h2>");//document.all.myt.insertAdjacentHTML("beforeBegin","<h2>在文本后容器内插入内容</h2>");//document.all.myt.insertAdjacentHTML("beforeBegin","<div id='scrollDiv' class='scrollDiv' >");</script></html>
Copy after login
Copy after login



Hello, after implementing the append, I want to have the effect of fixed header, can you help me? Change it?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css"> <!-- body,table, td, a {font:9pt;} /*重点:固定行头样式*/.scrollRowThead{position: relative; left: expression(this.parentElement.parentElement.parentElement.parentElement.scrollLeft);z-index:0;}/*重点:固定表头样式*//*行列交叉的地方*/.scrollCR { z-index:3;}/*div外框*/.scrollDiv {height:200px;clear: both; border: 1px solid #EEEEEE;OVERFLOW: scroll;width: 300px; }/*行头居中*/.scrollColThead td,.scrollColThead th{ text-align: center ;}/*行头列头背景*/.scrollRowThead,.scrollColThead td,.scrollColThead th{background-color:#FFFFFF;}/*表格的线*/.scrolltable{border-bottom:1px solid #CCCCCC; border-right:1px solid #CCCCCC; }/*单元格的线等*/.scrolltable td,.scrollTable th{border-left: 1px solid #CCCCCC; border-top: 1px solid #CCCCCC; padding: 5px; }thead tr{position: relative;top: expression(this.parentElement.parentElement.parentElement.scrollTop);z-index:3;background-color:#CCCCCC;}--> </style><script src="http://code.jquery.com/jquery-1.11.0.min.js"></script><script>//+---------------------------------------------------//| jQuery插件:表头固定 (还需测试)//| author:阿明//+---------------------------------------------------(function ($) {    $.fn.extend({        ScrollTable: function (options) {            var defaults = {                MaxHeight: 120,                MaxDataItemIndex: 1 // 固定前MaxDataItemIndex作为固定表头            };            options = $.extend(defaults, options);             return this.each(function () {                var $this = $(this);                 // 产生表头部分和身体部分                var $cloneTableHeader = $this.clone();                var $cloneTableBody = $this.clone();                $cloneTableHeader.find("tr").filter(function (index) { return index >= options.MaxDataItemIndex }).remove();                $cloneTableBody.find("tr").filter(function (index) { return index < options.MaxDataItemIndex }).remove();                 // 将产生的表头和身体部分放入Container,并做一些微调                $this.after("<div class='ScrollTableContainer' style='border:1px solid;'></div>");                $this.next().append($cloneTableHeader);                $this.next().append("<div class='ScrollDiv' style='overflow-y:scroll;'></div>");                $this.next().css("width", $this.width() + 20);                $this.next().find("div.ScrollDiv").css({                    "max-height": options.MaxHeight,                    "width": $this.width() + 20,                    "margin-top": -2                });                $this.next().find("div.ScrollDiv").append($cloneTableBody);                $this.remove();            });        }    });})(jQuery);$(function(){	$('#myt').ScrollTable();})</script></head><body><h1>利用CSS代码让Table产生固定表头</h1><h3>www.865171.cn</h3><table><tr><td><table id="myt" border="0" cellpadding="3" cellspacing="0" width="300" class="scrollTable">    <thead >    <tr >      <th >h1</th>      <th >h2</th>      <th >h3</th>      <th >h4</th>      <th >h5</th>    </tr>    </thead>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox" value="checkbox">    a</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox2" value="checkbox">    b</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td nowrap class="scrollRowThead"  >    <input type="checkbox" name="checkbox3" value="checkbox">    c</td>      <td nowrap>单元格2</td>      <td nowrap>单元格3</td>      <td nowrap>单元格4</td>      <td nowrap>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox4" value="checkbox">    d</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox5" value="checkbox">    e</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead"  >    <input type="checkbox" name="checkbox6" value="checkbox">    f</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    <tr>      <td class="scrollRowThead" >    <input type="checkbox" name="checkbox7" value="checkbox">    g</td>      <td>单元格2</td>      <td>单元格3</td>      <td>单元格4</td>      <td>单元格5</td>    </tr>    </table>	</td>    </tr></table></body><script>//document.all.myt.insertAdjacentHTML("afterBegin","<h1>在文本前容器内插入内容</h1>");//document.all.myt.insertAdjacentHTML("beforeEnd","<h2>在文本后容器内插入内容</h2>");//document.all.myt.insertAdjacentHTML("beforeBegin","<h2>在文本后容器内插入内容</h2>");//document.all.myt.insertAdjacentHTML("beforeBegin","<div id='scrollDiv' class='scrollDiv' >");</script></html>
Copy after login



Actually this page is not what I want to use. I just want to use this interface to learn how to append DIVs and implement fixed table headers. Now I The situation is that the tables on the page are written by the platform using Java code, and are output to HTML when used. That is to say, the page has many tables, and one table contains the header and data. It seems that it doesn't matter if you put it in according to your code. Use it, I don’t know where the meter header is.


----------------------------------??????? ???????????????????????????????????????






_______________________________________________________________________________________

Could you please take a look at this page?

??????????????????????????????????????????? ???????




test








<script> <br> / /------------------------------------------------- -- <br> //| jQuery plug-in: table header fixed (still needs to be tested) <br> //| author: A Ming <br> // ---------------- ---------------------------------- <br> (function ($) { <br> $.fn .extend({ <br> ScrollTable: function (options) { <br> var defaults = { <br> MaxHeight: 120, <br> MaxDataItemIndex : 1 // MaxDataItemIndex is used as the fixed header before fixing <br> }; <br> options = $.extend(defaults, options); <br> <br> return this.each(function () { <br> var $this = $(this); <br> <br> // Generate header Parts and body parts<br> var $cloneTableHeader = $this.clone(); var $cloneTableBody = $this.clone(); var $cloneTableHeader.find(" tr").filter(function (index ) { return index >= options.MaxDataItemIndex }).remove(); <br>                 $cloneTableBody.find("tr").filter(function (index) { return index < options.MaxDataItemIndex }).remove(); <br /> <br /> // 将产生的表头和身体部分放入Container,并做一些微调 <br /> $this.after("<div class='ScrollTableContainer' style='border:1px solid;'></div>"); <br>                 $this.next().append($cloneTableHeader); <br>                 $this.next().append("<div class='ScrollDiv' style='overflow-y:scroll;'></div>"); <br>                 $this.next().css("width", $this.width() + 20); <br>                 $this.next().find("div.ScrollDiv").css({ <br>                     "max-height": options.MaxHeight, <br>                     "width": $this.width() + 20, <br>                     "margin-top": -2 <br>                 }); <br>                 $this.next().find("div.ScrollDiv").append($cloneTableBody); <br>                 $this.remove(); <br>             }); <br>         } <br>     }); <br> })(jQuery); <br> $(function(){ <br>     $('#myt').ScrollTable(); <br> }) <br> </script>










打印 | Excel2003输出 | Excel2007输出







制造商RO回答查询








<script> <br> AWS_REPORT_TITLE.style.display='none'; <br> </script>



< td>









Supplier Code
RO Residual Number
Unit












< td >B0ECKR000020

t;








td > 




21016245< ;/td>







 
 
 
 
 
 



3.
4500025091
NP02
D9ZZ00000152
N20
21016245
2000

2014-03-03
2014-03-03
0
2000
 
 
 
 
 
 
 


4.
4500025087
NP02
B0ECKR000020
N20
21016245
1500

2014-03-03
2014-03-03
0
1500
 
 
 
 
 
 
 


5.
4500025088
NP02
B0ECKR000020
N20
21016245
3000

2014-03-17
2014-03-17
0
3000
 
 
 
 
 
 
 


6.
9000042229
NP01
B0ECKM000037
N20
21016245
1500

2014-02-28
2014-02-28
0
1500
 
 
 
 
 
 
 


7.
9000042230
NP01
B0ECKM000037
N20
21016245
3000

2014-03-17
2014-03-17
0
3000
 
 
 
 
 
 
 


8.
9000042231
NP01
B0ECKM000037
N20
21016245
3000

2014-03-31
2014-03-31
0
3000
 
 
 
 
 
 
 


9.
9000042232
NP01
B1JADV000002
N20
21016245
1000

2014-02-28
2014-02-28
0
1000
 
 
 
 
 
 
 


10.
9000042233
NP01
B1JADV000002
N20
21016245
2000

2014-03-17
2014-03-17
0
2000
 
 
 
 
 
 
 






RONO Purchasing Organization Purchasing Group Initial delivery period Latest delivery period VMI warehouse inventory Count Number of undelivered goods to VMI warehouse First time answer First time Quantity Previous answer Previous quantity Latest answer< /td>
1. 4500025089 NP02 N20 21016245 2014-03-03 2014-03-03 0 1500          
2. 4500025090
NP02 D9ZZ00000152 2000 2014-03-03 2014-03-03 0 2000  





 









??????????????????????????????????????????????????????
不知道我改了什么,那个表头好像又出来了,现在就差表头和数据列对齐
总之还是谢谢你,学到了点东西,或许是我这情况太特殊了,我迟点就把分给你吧

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template