javascript simulation scoring control implementation method
- 2020-06-15 07:35:07
- OfStack
An example of javascript simulation scoring control is presented in this paper. Share to everybody for everybody reference. Specific implementation methods are as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Dynamic setting style( Effect of grading )</title>
<script type="text/javascript">
// To find the 1 The index position of an element in an array
function ArrayIndexOf(arr, element) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == element) {
return i;
}
}
return -1;
}
function IniEvent() {
var tbl = document.getElementById("tblRating");
var tds = tbl.getElementsByTagName("td");
for (var i = 0; i < tds.length; i++) {
var td = tds[i];
td.onclick = tdOnClick;
td.style.cursor = "pointer"; // Set the cursor hand shape
}
}
function tdOnClick() {
var tbl = document.getElementById("tblRating");
var tds = tbl.getElementsByTagName("td");
// Find what is currently clicked td The index of the
var index = ArrayIndexOf(tds, this);
// Before the td Instead of red
for (var i = 0; i <= index; i++) {
tds[i].style.background = "red";
}
// After the td Instead of white
for (var i = index + 1; i < tds.length; i++) {
tds[i].style.background = "white";
}
}
</script>
</head>
<body onload="IniEvent()">
<table id="tblRating">
<tr>
<td> Do things </td>
<td> Do things </td>
<td> Do things </td>
<td> Do things </td>
<td> Do things </td>
</tr>
</table>
</body>
</html>
Hopefully, this article has been helpful in your javascript programming.