有两个单选按钮,怎样判断选中了哪一个? 应该加 value="" 通过value 的值来判断吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用个<form action="check.jsp"><input type="radio" name="aaa">..... </form>将以上单选按钮给包含进来,在check.jsp页面中String AAA=request.getParameter("aaa");AAA就取出来,上一页所选择的值!,楼主的为什么要判断选了哪一个的呢! 在用request取到数据后,同一组按钮的名字是相同的,根据你所提取出来的值判断选的是哪一个,也就是每个单选都有不同的value的! 我认为如果只能单选,应该使用xuyang821225说的方法,如果可以多选,那么使用不同的名字,用名字判断 <HTML><HEAD><TITLE> New Document </TITLE><SCRIPT LANGUAGE="JavaScript"><!--function temp(){if(document.forms[0].rad1[0].checked){ alert("No1 selected");}else if(document.forms[0].rad1[1].checked){ alert("No2 selected");}}//--></SCRIPT></HEAD><BODY><FORM METHOD=POST ACTION=""> <input type="button" value="" onclick="temp();"/><BR><input type="radio" name="rad1">No.1<BR><input type="radio" name="rad1">No.2</FORM></BODY></HTML> 可以建一个BEAN,将页面的值放入BEAN中提交,在servlet中可以拿到 function GetRadioValue(ObjectName){ var Object=document.getElementsByName(ObjectName); for(iIndex=0;iIndex<Object.length;iIndex++) { if(Object[iIndex].checked==true) { return Object[iIndex].value; } } return null;} BEAN可以是个数组,就象struts中property可以是个数组一样,在后台只要拿bean中的下标就知道哪个选上了. 还有你可以给他不同的value,比如:<jsp:useBean id="bean" scope="request" class="beanpath.bean" /><html:radio property="choicebox" value="1" ><html:radio property="choicebox" value="2" ><html:radio property="choicebox" value="3" ></jsp:useBean>然后定义一个bean去取得,以下是beanpath.bean的内容 //txt_DELIV_CHOICE private String[] choicebox = ""; public String[] getchoicebox(){ return this.choicebox; } public void setchoicebox(String[] choicebox){ this.choicebox = choicebox; }只要在servlet中判断:String choicebox[] = beanpath.bean.getchoicebox();for(int i=0;i<choicebox.length,i++){ if(choicebox[i]!=null && choicebox[i].toString().equals("1")){ 第一个被选中! } else if(choicebox[i]!=null && choicebox[i].toString().equals("2")){ 第二个被选中! } else if(choicebox[i]!=null && choicebox[i].toString().equals("3")){ 第三个被选中! }} 如果光光要在客户端判断的话,以下代码就可以满足,保存为JSP,直接用IE运行,无需启动WEB服务器:<HTML><HEAD><TITLE> New Document </TITLE><SCRIPT LANGUAGE="JavaScript"><!--function temp(){if(document.forms[0].rad1[0].checked){ alert("No1 selected");}else if(document.forms[0].rad1[1].checked){ alert("No2 selected");}}//--></SCRIPT></HEAD><BODY><FORM METHOD=POST ACTION=""> <input type="button" value="按我" onclick="temp();"/><BR><input type="radio" name="rad1">No.1<BR><input type="radio" name="rad1">No.2</FORM></BODY></HTML> struts2 的action 会执行两次 回应:驳-----问题越来越没含金量的贴子->limitclear这种人也配当程序员?2 帮忙看下这样的字符怎么转换? JSP中的错误 JSTL的标签到底能不能访问jsp脚本<%%>中定义的变量啊?? 很簡單問題,我沒用過jsp,請幫忙 如何进行这样的类型转换 请问怎样设才可以编译servlet,谢谢 jsp得到数据库结果集后的分页如何编写!? Spring3+MyBatis的详细配置? Servlet 错误页问题 关于自定义标签的问题
将以上单选按钮给包含进来,
在check.jsp页面中
String AAA=request.getParameter("aaa");
AAA就取出来,上一页所选择的值!
,楼主的为什么要判断选了哪一个的呢!
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function temp(){
if(document.forms[0].rad1[0].checked)
{
alert("No1 selected");
}
else if(document.forms[0].rad1[1].checked)
{
alert("No2 selected");
}
}
//-->
</SCRIPT>
</HEAD><BODY>
<FORM METHOD=POST ACTION="">
<input type="button" value="" onclick="temp();"/>
<BR>
<input type="radio" name="rad1">No.1
<BR>
<input type="radio" name="rad1">No.2
</FORM>
</BODY>
</HTML>
{
var Object=document.getElementsByName(ObjectName);
for(iIndex=0;iIndex<Object.length;iIndex++)
{
if(Object[iIndex].checked==true)
{
return Object[iIndex].value;
}
}
return null;
}
<jsp:useBean id="bean" scope="request" class="beanpath.bean" />
<html:radio property="choicebox" value="1" >
<html:radio property="choicebox" value="2" >
<html:radio property="choicebox" value="3" >
</jsp:useBean>然后定义一个bean去取得,以下是beanpath.bean的内容 //txt_DELIV_CHOICE
private String[] choicebox = ""; public String[] getchoicebox(){
return this.choicebox;
} public void setchoicebox(String[] choicebox){
this.choicebox = choicebox;
}
只要在servlet中判断:
String choicebox[] = beanpath.bean.getchoicebox();
for(int i=0;i<choicebox.length,i++){
if(choicebox[i]!=null && choicebox[i].toString().equals("1")){
第一个被选中!
}
else if(choicebox[i]!=null && choicebox[i].toString().equals("2")){
第二个被选中!
}
else if(choicebox[i]!=null && choicebox[i].toString().equals("3")){
第三个被选中!
}
}
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function temp(){
if(document.forms[0].rad1[0].checked)
{
alert("No1 selected");
}
else if(document.forms[0].rad1[1].checked)
{
alert("No2 selected");
}
}
//-->
</SCRIPT>
</HEAD><BODY>
<FORM METHOD=POST ACTION="">
<input type="button" value="按我" onclick="temp();"/>
<BR>
<input type="radio" name="rad1">No.1
<BR>
<input type="radio" name="rad1">No.2
</FORM>
</BODY>
</HTML>