编程论坛
注册
登录
编程论坛
→
ASP技术论坛
谁知道jsp设置radio控件功能?
gesongs
发布于 2011-08-31 09:58, 641 次点击
我想设计一个radio控件功能是 选中它 后面跟着的 text 文本框 就必须填写 反之 就不用填写
恳求分享,先谢过!
4 回复
#2
yms123
2011-08-31 16:19
你在提交时判断一下是否选中不就好了?
javascript判断radio或checkbox是否选中
[radio或checkbox的name属性或id属性].checked
比如有个radio
<input type="radio" id="radio1" >
判断时
if(radio1.checked)
{
alert('选中');
}
else
{
alert("未选中");
}
#3
gesongs
2011-09-01 09:07
不是判断 radio 是否选中的功能
是想实现 radio 和 text 的组合功能
希望实现的功能是 text 文本 前面 有个 radio
再我 选中 radio 时 text 才能 填写数据
反之 没选中 text 就不能填写内容!
#4
yms123
2011-09-01 12:21
可以把文本框设置为readOnly
程序代码:
<html>
<head>
<title>单选框填写数据</title>
<script language=
"
javascript
"
>
function
radio1_click()
{
var ra1=this.radio1;//获得单选框
var txt1=document.getElementById(
"
text1
"
);//获得文本框
//如果可以输入数据被选中
if
(ra1[
0
].checked)
{
txt1.readOnly=
false
;//设置文本框只读属性为false;
}
else
{
//不可以输入数据被选中设置只读属性为true
txt1.value=
""
;
txt1.readOnly=
true
;
}
}
</script>
</head>
<body>
<input type=
"
radio
"
onclick=
"
radio1_click();
"
name=
"
radio1
"
/>可以输入数据
<input type=
"
radio
"
onclick=
"
radio1_click();
"
name=
"
radio1
"
checked />不可以输入数据
<input type=
"
text
"
id=
"
text1
"
readonly />
</body>
</html>
#5
gesongs
2011-09-01 18:29
太好了就是这个效果!因为不懂jsp 所有 还请麻烦你 再加些功能,
就是 我选中填写数据 就必须填写 否则 提交表单就 提示要填写数据!
其次 就是 还要加一个<input type="text" id="text2" readonly />
因为有量个数据填写
另,怎么把你给的这段代码 放到 <form name="form1" method="post" action="">
</form>里面 功能就 失去了!
上述情况麻烦你了!
[
本帖最后由 gesongs 于 2011-9-1 19:08 编辑
]
1