时间:2021-07-01 10:21:17 帮助过:21人阅读
var level = table1row1.getAttribute("level");
if (level === undefined || level == null) {
level = "0";
}
level = level.toString();
if (level.trim() == "") {
level = "0";
}
<!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>
<title>Test</title>
<script type="text/javascript" language="javascript">
function pageLoad() {
var table1row1 = document.getElementById("table1row1");
table1row1.setAttribute("level", 1);
table1row1.setAttribute("onclick", "selectrow1(this)");
var table1row2 = document.getElementById("table1row2");
table1row2.setAttribute("level", 2);
table1row2.setAttribute("onclick", "selectrow1(this)");
var table2row1 = document.getElementById("table2row1");
table2row1.setAttribute("level", 3);
table2row1.onclick = function() { selectrow2(this) };
var table2row2 = document.getElementById("table2row2");
table2row2.setAttribute("level", 4);
table2row2.onclick = function() { selectrow2(this) };
}
var CurrentSelectRow1 = null;
function selectrow1(newSelectRow) {
if (CurrentSelectRow1 != null) {
CurrentSelectRow1.style.backgroundColor = '#ffffff';
}
newSelectRow.style.backgroundColor = 'PeachPuff';
CurrentSelectRow1 = newSelectRow;
}
var CurrentSelectRow2 = null;
function selectrow2(newSelectRow) {
if (CurrentSelectRow2 != null) {
CurrentSelectRow2.style.backgroundColor = '#ffffff';
}
newSelectRow.style.backgroundColor = '#ff0000';
CurrentSelectRow2 = newSelectRow;
}
function button1_click() {
var table1row1 = document.getElementById("table1row1");
var level = table1row1.getAttribute("level");
var desc1 = "table1row1 level:" + level + "\r\ntypeof(level) = " + (typeof (level)).toString();
alert(desc1);
var onclick1 = table1row1.getAttribute("onclick");
var desc2 = "table1row1 onclick:" + onclick1.toString() + "\r\ntypeof(onclick) = " + (typeof (onclick1)).toString();
alert(desc2);
}
function button2_click() {
var table2row1 = document.getElementById("table2row1");
var level = table2row1.getAttribute("level");
var desc1 = "table2row1 level:" + level + "\r\ntypeof(level) = " + (typeof (level)).toString();
alert(desc1);
var onclick1 = table2row1.onclick;
var desc2 = "table2row1 onclick:" + onclick1.toString() + "\r\ntypeof(onclick) = " + (typeof (onclick1)).toString();
alert(desc2);
}
</script>
</head>
<body onload="pageLoad();">
<div style="width: 600px">
<span>table1</span>
<table cellspacing="0" rules="all" border="1" id="table1" style="border-width: 1px;
border-style: Solid; width: 100%; border-collapse: collapse;">
<tr id="table1row0">
<td align="center" style="width: 50%;">
No.
</td>
<td align="center" style="width: 50%;">
Item
</td>
</tr>
<tr id="table1row1">
<td align="center" style="width: 50%;">
1
</td>
<td align="left" style="width: 50%;">
2C.40E80.041
</td>
</tr>
<tr id="table1row2">
<td align="center" style="width: 50%;">
2
</td>
<td align="left" style="width: 50%;">
4L.013Y2.003
</td>
</tr>
</table>
<input type="button" id="button1" onclick="return button1_click();" />
</div>
<div style="width: 600px">
<br />
<span>table2</span>
<table cellspacing="0" rules="all" border="1" id="table2" style="border-width: 1px;
border-style: Solid; width: 100%; border-collapse: collapse;">
<tr id="table2row0">
<td align="center" style="width: 50%;">
No.
</td>
<td align="center" style="width: 50%;">
Item
</td>
</tr>
<tr id="table2row1">
<td align="center" style="width: 50%;">
1
</td>
<td align="left" style="width: 50%;">
4G.0QE18.001
</td>
</tr>
<tr id="table2row2">
<td align="center" style="width: 50%;">
2
</td>
<td align="left" style="width: 50%;">
2K.61209.208
</td>
</tr>
</table>
<input type="button" id="button2" onclick="return button2_click();" />
</div>
</body>
</html>