Javascript 如何在选择单选按钮时禁用多个复选框? 历史前进(); 函数验证(日志文件){ var计数=0; 对于(var i=0;i
您可以使用这些Javascript 如何在选择单选按钮时禁用多个复选框? 历史前进(); 函数验证(日志文件){ var计数=0; 对于(var i=0;i,javascript,Javascript,您可以使用这些 首先,它循环获取所有元素(例如:复选框),然后向它们添加onclick事件侦听器。然后,内部循环是在单击复选框时禁用所有单选按钮,相同的逻辑应用于单选按钮: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page isELIgnored="false" %> <%@ page im
首先,它循环获取所有元素(例如:复选框),然后向它们添加onclick事件侦听器。然后,内部循环是在单击复选框时禁用所有单选按钮,相同的逻辑应用于单选按钮:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page isELIgnored="false" %>
<%@ page import="java.util.*"%>
<%@page import="com.ba.RetrieveDetails"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
history.forward();
function validate(logFile){
var count=0;
for (var i=0; i<logFile.length; i++) {
if (logFile[i].checked) {
count++;
}
}
if (count < 1)
{
alert("please select Log Fille(s)");
return false;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Log Files</title>
</head>
<body>
<form name="LogFiles" action="RetrieveLogFiles" method="get" onsubmit="">
<%
HashMap hs=new HashMap();
hs=(HashMap)session.getAttribute("key");
session.getAttribute("key");
String hosts[]=(String[])session.getAttribute("hosts");
%>
<br>
<br>
<img src="BA_Logo1.bmp" align="right" alt="British Airways">
<table>
<tr>
<%
if(hs.size()== 0)
{%>
<td><h3>Authentication fail OR Does not have access to UnixBox.Click <a href="Login.jsp">Here</a> to Login</h3></td>
<%
}
else
{
for(int i=0;i<hosts.length;i++)
{
%>
<h3><p><%out.println(hosts[i]+"\n");%></p></h3>
<%
ArrayList al=new ArrayList();
al=(ArrayList)hs.get(hosts[i]);
int flag=al.size();
%>
<td>
<table border="2" cellpadding="4">
<%
if(flag==0)
{%>
<td>
<h3><p style="color:#FF0000">No Log Files to display</p></h3>
</td>
<%
}else{
for(int j=0;j<al.size();j++)
{
String lines[]=al.get(j).toString().split("\\r?\\n");
for(int len=0;len<lines.length;len++)
{
%>
<tr>
<td><%out.println(lines[len]);%></td>
<td><input type="checkbox" name="logFile" id="logFile" value="<%=hosts[i]+"$"+lines[len]%>"></td>
<td><input type="radio" name="logFileView" id="logFileView" value="<%=hosts[i]+"$"+lines[len]%>"></td>
</tr>
<%
}%>
</table>
</td>
</tr>
</table>
<% }
}
}%>
<input type="submit" name="Get Logs" align="middle" value="Get Logs" onclick="return validate(logFile)" >
<%
}
%>
</form>
</body>
</html>
var logFiles=document.getElementsByName(“logFile”);
var logFileView=document.getElementsByName(“logFileView”);
//单击任何复选框时禁用所有单选按钮
for(var i=0,count=logFiles.length;i
Hi@Handy其工作正常,但在我第二次而非第一次单击时禁用,例如:如果单击两个复选框或在同一复选框上单击两次,则禁用效果最佳。请对此进行处理。@shivatatikonda:只需更新。我添加了一个变量来存储对复选框的单击次数。每次单击时,计数器都将增加1CKBOX。如果计数器达到2,则它将禁用所有单选按钮。
var logFiles = document.getElementsByName("logFile");
var logFileViews = document.getElementsByName("logFileView");
//To disable all radio buttons when click on any check box
for (var i=0, count=logFiles.length; i < count; i++) {
logFiles[i].onclick = function() {
for (var j=0, count=logFileViews.length; j < count; j++) {
logFileViews[j].disabled = true;
}
};
}
//To disable all check boxes when click on any radio button
for (var i=0, count=logFileViews.length; i < count; i++) {
logFileViews[i].onclick = function() {
logFiles.disabled = true;
for (var j=0, count=logFiles.length; j < count; j++) {
logFiles[j].disabled = true;
}
};
}