SoFunction
Updated on 2025-04-06

JavaScript implements the method of highlighting the rows selected by table to specify the color

JavaScript implements the method of highlighting the rows selected by table to specify the color

Updated: May 13, 2015 15:25:35 Author: Always love writing programs
This article mainly introduces the method of javascript to implement the selected rows of tables to specify the color highlighting. The example analyzes the skills of javascript to operate table elements and related styles. Friends who need it can refer to it.

This article describes the method of javascript implementing the selected row of table to specify color highlighting. Share it for your reference. The specific implementation method is as follows:

<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>tableThe selected row is highlighted in the specified color</title>
<script type="text/javascript">
function IniEvent() {
  var tbl = ("tblMain");
  var trs = ("tr");
  for (var i = 0; i < ; i++) {
 trs[i].onclick = TrOnClick;
  }
}
function TrOnClick() {
  var tbl = ("tblMain");
  var trs = ("tr");
  for (var i = 0; i < ; i++) {
 if (trs[i] == this) { //Judge whether it is the currently selected row   trs[i]. = "yellow";
 }
 else {
   trs[i]. = "white";
 }
  }
}
</script>
</head>
<body onload="IniEvent()">
<table  border="1">
<tr>
  <td>1</td>
  <td>Samsung</td>
  <td>AA</td>
</tr>
<tr>
  <td>2</td>
  <td>Norkia</td>
  <td>BB</td>
</tr>
<tr>
  <td>3</td>
  <td>apple</td>
  <td>CC</td>
</tr>
<tr>
  <td>4</td>
  <td>Lenovo</td>
  <td>DD</td>
</tr>
</table>
</body>
</html>

I hope this article will be helpful to everyone's JavaScript programming.

  • javascript
  • table
  • Highlight

Related Articles

  • JavaScript time sorting algorithm realizes the countdown effect of instant killing in activity

    This article mainly introduces the JavaScript time sorting algorithm to achieve the countdown effect of instant killing, that is, multiple countdowns are sorted on a page. The sample code in the article is introduced in detail and has certain reference value. Interested friends can refer to it.
    2016-03-03
  • Detailed introduction to the() function in JavaScript

    This article mainly introduces the detailed introduction of the() function in JavaScript. The() function is mainly used to count the execution time of the program. Friends who need it can refer to it.
    2014-12-12
  • JavaScript Online Compression and Format Collection

    The two sets of online compression and formatting tools written by foreigners are written in pure JavaScript. They can be downloaded and used offline, which is very convenient.
    2009-01-01
  • Detailed explanation of js event flow, event delegation and event stage instance

    Event commissioning is used in many development scenarios, but many students don’t know much about the principles of commissioning, especially JS native implementation of commissioning. The following article mainly introduces relevant information about js event flow, event commissioning and event stages. Friends who need it can refer to it.
    2022-02-02
  • How to implement list rendering and conditional rendering of WeChat applets

    WeChat applets also have list rendering and conditional rendering. The following article mainly introduces relevant information about how WeChat applets implement list rendering and conditional rendering. The article introduces the example code in detail. Friends who need it can refer to it.
    2022-06-06
  • How to dynamically generate tree menus in javascript

    This article mainly introduces the method of dynamically generating tree menus by JavaScript, which involves JavaScript's dynamic operation skills for page elements and attributes. It has certain reference value. Friends who need it can refer to it.
    2015-11-11
  • Passing JavaScript data on different pages (getting URL parameters)

    This article mainly introduces the delivery of JavaScript data on different pages (URL parameter acquisition). The following article revolves around the implementation of JavaScript data on different pages. If you want to know, you can enter the article with the editor to learn about the specific content. If you need it, you can also refer to it.
    2021-12-12
  • Bugs generated by JS comments will be executed even if the comments are

    A bug occurred while writing js and kept reminding me that there was no attribute in the JAVA class, but it was clearly commented out. Later I found out that even the comments in JS will be executed.
    2013-11-11
  • Native js implement free drag and drop popup code demo

    This article mainly introduces the native JS implementation of pop-up drag code demo, as well as the things to note when implementing the js pop-up drag effect. Interested friends can refer to it.
    2016-06-06
  • How to implement JavaScript to dynamically load CSS and JS files

    This article mainly introduces JavaScript dynamic loading of CSS and JS files. The sample code in the article is introduced in detail and has a certain reference value. Interested friends can refer to it.
    2015-10-10

Latest Comments