Javascript merge table cell example code_javascript skills
This article introduces you to a code example from the Internet that can merge cells. Let’s share it with you. I hope it can bring some help to friends in need.
The code example is as follows:
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"/> <title>表格单元格合并代码</title> <script type="text/javascript"> function autoRowSpan(tb,row,col){ var lastValue=""; var value=""; var pos=1; for(var i=row;i<tb.rows.length;i++){ value=tb.rows[i].cells[col].innerText; if(lastValue==value){ tb.rows[i].deleteCell(col); tb.rows[i-pos].cells[col].rowSpan=tb.rows[i-pos].cells[col].rowSpan+1; pos++; } else{ lastValue=value; pos=1; } } } window.onload=function(){ var tb=document.getElementById("tb"); autoRowSpan(tb,0,0) } </script> </head> <body> <table id="tb" border="1"> <thead> <tr > <td>国家</td> <td>地区</td> </tr> </thead> <tr> <td>中国</td> <td>河南</td> </tr> <tr> <td>中国</td> <td>四川</td> </tr> <tr> <td>中国</td> <td>北京</td> </tr> <tr> <td>美国</td> <td>纽约</td> </tr> <tr> <td>美国</td> <td>洛杉矶</td> </tr> <tr> <td>英国</td> <td>伦敦</td> </tr> </table> </body> </html>
I am sharing a paragraph with you:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>合并表格</title> <script> /////////////////////////////////////////////// //功能:合并表格 //参数:tb-需要合并的表格ID //参数:colLength--需要对前几列进行合并,比如, //想合并前两列,后面的数据列忽略合并,colLength应为2 //缺省表示对全部列合并 //data:2011.11.06 /////////////////////////////////////////////// function uniteTable(tb,colLength){ //检查表格是否规整 if(!checkTable(tb)) return; var i=0; var j=0; var rowCount=tb.rows.length; //行数 var colCount=tb.rows[0].cells.length; //列数 var obj1=null; var obj2=null; //为每个单元格命名 for(i=0;i<rowCount;i++){ for(j=0;j<colCount;j++){ tb.rows[i].cells[j].id="tb__" + i.toString() + "_" + j.toString(); } } //逐列检查合并 for(i=0;i<colCount;i++){ if(i==colLength) return; obj1=document.getElementById("tb__0_"+i.toString()) for(j=1;j<rowCount;j++){ obj2=document.getElementById("tb__"+j.toString()+"_"+i.toString()); if(obj1.innerText==obj2.innerText){ obj1.rowSpan++; obj2.parentNode.removeChild(obj2); }else{ obj1=document.getElementById("tb__"+j.toString()+"_"+i.toString()); } } } } ///////////////////////////////////////// //功能:检查表格是否规整 //参数:tb--需要检查的表格ID //data: 2011.11.06 ///////////////////////////////////////// function checkTable(tb){ if(tb.rows.length==0) return false; if(tb.rows[0].cells.length==0) return false; for(var i=0;i<tb.rows.length;i++){ if(tb.rows[0].cells.length!=tb.rows[i].cells.length) return false; } return true; } </script> </head> <body> <table width="400" border="1" id="table1"> <tr> <td>a</td> <td>for</td> <td>100</td> <td>200</td> <td>1</td> </tr> <tr> <td>a</td> <td>for</td> <td>100</td> <td>300</td> <td>2</td> </tr> <tr> <td>a</td> <td>if</td> <td>100</td> <td>200</td> <td>3</td> </tr> <tr> <td>a</td> <td>if</td> <td>300</td> <td>230</td> <td>4</td> </tr> <tr> <td>a</td> <td>if</td> <td>320</td> <td>230</td> <td>5</td> </tr> </table> <br><input type="button" value="合并表格" onClick="uniteTable(table1,4)"> </body> </html>
I hope this article will be helpful to everyone learning JavaScript programming.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

1. Create a new PPT file and name it [PPT Tips] as an example. 2. Double-click [PPT Tips] to open the PPT file. 3. Insert a table with two rows and two columns as an example. 4. Double-click on the border of the table, and the [Design] option will appear on the upper toolbar. 5. Click the [Shading] option and click [Picture]. 6. Click [Picture] to pop up the fill options dialog box with the picture as the background. 7. Find the tray you want to insert in the directory and click OK to insert the picture. 8. Right-click on the table box to bring up the settings dialog box. 9. Click [Format Cells] and check [Tile images as shading]. 10. Set [Center], [Mirror] and other functions you need, and click OK. Note: The default is for pictures to be filled in the table

1. Open the worksheet and find the [Start]-[Conditional Formatting] button. 2. Click Column Selection and select the column to which conditional formatting will be added. 3. Click the [Conditional Formatting] button to bring up the option menu. 4. Select [Highlight conditional rules]-[Between]. 5. Fill in the rules: 20, 24, dark green text with dark fill color. 6. After confirmation, the data in the selected column will be colored with corresponding numbers, text, and cell boxes according to the settings. 7. Conditional rules without conflicts can be added repeatedly, but for conflicting rules WPS will replace the previously established conditional rules with the last added rule. 8. Repeatedly add the cell columns after [Between] rules 20-24 and [Less than] 20. 9. If you need to change the rules, you can just clear the rules and then reset the rules.

Being able to skillfully make forms is not only a necessary skill for accounting, human resources, and finance. For many sales staff, learning to make forms is also very important. Because the data related to sales is very large and complex, and it cannot be simply recorded in a document to explain the problem. In order to enable more sales staff to be proficient in using Excel to make tables, the editor will introduce the table making issues about sales forecasting. Friends in need should not miss it! 1. Open [Sales Forecast and Target Setting], xlsm, to analyze the data stored in each table. 2. Create a new [Blank Worksheet], select [Cell], and enter [Label Information]. [Drag] downward and [Fill] the month. Enter [Other] data and click [

Is it frustrating to automatically remove leading zeros from Excel workbooks? When you enter a number into a cell, Excel often removes the leading zeros in front of the number. By default, it treats cell entries that lack explicit formatting as numeric values. Leading zeros are generally considered irrelevant in number formats and are therefore omitted. Additionally, leading zeros can cause problems in certain numerical operations. Therefore, zeros are automatically removed. This article will teach you how to retain leading zeros in Excel to ensure that the entered numeric data such as account numbers, zip codes, phone numbers, etc. are in the correct format. In Excel, how to allow numbers to have zeros in front of them? You can preserve leading zeros of numbers in an Excel workbook, there are several methods to choose from. You can set the cell by

Sometimes, we often encounter counting problems in Word tables. Generally, when encountering such problems, most students will copy the Word table to Excel for calculation; some students will silently pick up the calculator. Calculate. Is there a quick way to calculate it? Of course there is, in fact the sum can also be calculated in Word. So, do you know how to do it? Today, let’s take a look together! Without further ado, friends in need should quickly collect it! Step details: 1. First, we open the Word software on the computer and open the document that needs to be processed. (As shown in the picture) 2. Next, we position the cursor on the cell where the summed value is located (as shown in the picture); then, we click [Menu Bar

Word software is indispensable to us and needs to be used frequently. I have learned how to edit tables using Word software before. However, if I accidentally edit the table in the horizontal and vertical directions, and I don’t want to waste time re-creating it, is it possible to change the horizontal and vertical directions of the table? Woolen cloth? The answer is of course yes. Next, the editor will introduce to you in detail how to swap tables horizontally and vertically in Word. Let us learn together. First, we need to swap the rows and columns of the Word table below. To do this, we need to first select the table entirely, then right-click and select the copy function. Step 2: After selecting copy, we minimize word, then open an Excel table, right-click, select paste, and paste it into Exc

WPS software is an indispensable helper for text and document processing. In practical applications, it is often necessary to operate in cells to process text and documents. There is a lot of knowledge about cells. Today, let me introduce the specific steps on how to divide a cell into two in WPS. 1. First, we open the WPS table that needs to be edited and select the cell document that needs to be divided into two cells. 2. Click to open "Column" in the data. 3. Then select "Fixed Width" in the pop-up window and click "Next". 4. In the pop-up window, click where you want to separate columns and press Enter to confirm. Draw inferences from one example. If you need to change it to 3, you can also change the number to 3. 5. Then click Finish. 6. There is another way

We often create and edit tables in excel, but as a novice who has just come into contact with the software, how to use excel to create tables is not as easy as it is for us. Below, we will conduct some drills on some steps of table creation that novices, that is, beginners, need to master. We hope it will be helpful to those in need. A sample form for beginners is shown below: Let’s see how to complete it! 1. There are two methods to create a new excel document. You can right-click the mouse on a blank location on the [Desktop] - [New] - [xls] file. You can also [Start]-[All Programs]-[Microsoft Office]-[Microsoft Excel 20**] 2. Double-click our new ex
