0
在這張表中,當我檢查第一行的單選按鈕(present)時,當我再次檢查第二行的當前行時,第一行將自動取消選中。所有的單選按鈕都會被檢查。這只是兩個學生的樣本。gridview中的單選按鈕
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>HTML Tables</title>
</head>
<body>
<%@ page import="java.sql.*"%>
<table bgcolor="lightgray" border="5" width="60%" cellpadding="5" cellspacing="0.5" color="blue" >
<tr>
<th colspan ="3" bgcolor="#999999"><br>
<div align="Center" > <font face="verdana" size="5" color="white"> ATTENDANCE </font>
</div>
</th>
</tr>
<tr>
<td width="14%"><h3>Register No</td>
<td><h3> Student Name</td>
<td><h3> Attendance</td>
</tr>
<tr>
<td> 1 </td>
<td> <input type="radio" >Present <input type="radio">Absent
<tr>
<td>2</td>
<td> <input type="radio" >Present <input type="radio">Absent
</tr>
<%
Connection dbcon=null;
\t \t \t
\t DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
\t \t dbcon=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
\t \t Statement stmt=dbcon.createStatement();
\t \t ResultSet rst=null;
\t \t
rst=stmt.executeQuery("select * from studenttables");
while(rst.next())
{%>
<tr>
<td><%=rst.getString("name")%></td>
</tr>
<tr>
<td><%=rst.getString("name")%></td>
</tr>
<tr>
<td><%=1%></td>
<td><%=rst.getString("name")%></td>
<td><input type="radio" >Present <input type="radio">Absent
</tr>
\t \t
<% } %>
</table>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
單選按鈕需要共享一個名稱,它們形成一個互斥的組。目前你還沒有給他們任何名字,所以他們實際上全都在沒有名字的小組中。嘗試爲每一對命名:'input type =「radio」name =「student_1」value =「present」>'然後使用value屬性來區分這兩種不同的情況。 – halfer