0
위쪽 화살표와 아래쪽 화살표가 선택된 테이블 행이 있지만이를 클릭 할 수도 있습니다. 행을 클릭하면 현재 선택된 것으로 표시되지 않습니다. 또한 밑에있는 버튼의 URL의 일부로 마지막으로 선택한 행의 첫 번째 셀 내용을 사용할 수 있기를 원합니다. 아무도 도와 줄 수 있습니까?위쪽 화살표와 아래쪽 화살표로 선택된 테이블 행이 있지만이를 클릭 할 수도 있습니다.
(
function() {
var trows = document.getElementById("mstrTable").rows;
var selectedRow = 1;
for (var t = 1; t < trows.length; ++t) {
trow = trows[t];
trow.className = t === 1 ? "highlighted" : "normal";
trow.onclick = highlightRow;
}//end for
function highlightRow(rowObj, index) {
rowObj = rowObj || this;
index = index || selectedRow;
trows[index].className = "normal";
rowObj.className = "highlighted";
selectedRow = rowObj.rowIndex;
}//end function
function kbNavigate(evt) {
evt = evt || window.event;
var key = evt.keyCode;
switch (key) {
case 38: // UP arrow
if(selectedRow === 1) return;
highlightRow(trows[selectedRow-1], selectedRow);
break;
case 40: // DOWN arrow
if(selectedRow === trows.length-1) return;
highlightRow(trows[selectedRow+1], selectedRow);
break;
}
}
document.onkeydown = kbNavigate;
}//end function
)();//end script
body {background: #000042;}
.cas {
font-size: 20pt;
/*font-family: fixedsys, LucidaTerminal, monospace;*/
font-family: Courier, monospace;
color: Gold;
}
cas_h1 {
font-size: 30pt;
}
table {
border-collapse: collapse;
}
table, th, td {
border: 2px solid Gold;
color: Gold;
padding: 8px;
}
td, th {
font-size: 20pt;
/*font-family: fixedsys, LucidaTerminal, monospace;*/
font-family: Courier, monospace;
}
.cont {
border: none;
}
tr.normal td {
color: Gold;
background-color: #000042;
}
tr.highlighted td {
color: black;
background-color: OliveDrab;
font-weight: bold;
}
<html>
<head>
<title>cas</title>
<link href="cas.css" rel="stylesheet" type="text/css">
</head>
<body>
<center>
<p class='cas'>
<br>
<cas_h1>CAS</cas_h1><br>
<br>
<table class='cont'>
<tr>
<td class='cont'>
<table id="mstrTable">
<thead>
<tr>
<td>Order</td>
<td>Customer</td>
</tr>
</thead>
<tbody>
<td>1234567</td>
<td>Smith</td>
</tr>
<td>1234566</td>
<td>Smith</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class='cont'>
<button type='button' style='height: 30px;width: 80px' onclick='window.location.href="action1.php?order=1234567"'>Action 1</button>
<button type='button' style='height: 30px;width: 80px' onclick='window.location.href="action2.php?order=1234567"'>Action 2</button>
</td>
</tr>
</table>
</p>
</center>
<script type="text/javascript" src="cas_table.js"></script>
</body>
</html>
이것은 클릭 문제에 매우 효과적입니다. 난 그냥 버튼의 URL에 (현재 하드 코딩 된)에 포함하도록 선택한 마지막 행의 첫 번째 셀의 내용을 얻을 수 있어야합니다. –
@ John_F 답변 업데이트 – Mobius
당신은 스타입니다. 실제로 URL 비트가 나 자신을 작동시키고 업데이트 된 코드를 게시 할 예정 이었지만 당신이 나를 맞았 음을 알았습니다. 많은 감사 :-) –