html:select、radio之六取值问题
来源:互联网 发布:域名 服务器 编辑:程序博客网 时间:2024/05/18 03:17
一、页面加载时初始值问题:
1、select标签option初始值设置方法如下:
<%
String userRole = "";
%>
<html:form>
<html:select property="userRole" onchange="selectValue()">
<html:option value="operator">operator</html:option>
<html:option value="admin">admin</html:option>
</html:select>
</html:form>
<!-- 以下javascript代码需放在 </html:form>后,表示form表单加载完毕后执行,必须确保初始值<%=userRole%>能在js中取到 -->
<script language="javascript">
var userRole = document.all.userRole;
for(var i=0;i<userRole.length;i++){
if(userRole[i].value == <%=userRole%>){
userRole[i].selected = true;
break;
}
}
</script>
2、radio标签的初始值设置方法如下:
<%
String userRole = "";
%>
<html:form>
<html:radio property="userRole" value="operator" onclick="radioValue()"/>
<html:radio property="userRole" value="admin" onclick="radioValue()"/>
</html:form>
<!-- 以下javascript代码需放在 </html:form>后,表示form表单加载完毕后执行,必须确保初始值<%=userRole%>能在js中取到 -->
<script language="javascript">
var userRole = document.all.userRole;
for(var i=0;i<userRole.length;i++){
if(userRole[i].value == <%=userRole%>){
userRole[i].checked = true;
break;
}
}
</script>
二、页面事件及表单提交时取值问题:
1、select标签option取值方法如下:
<html:select property="userRole" onchange="selectValue()">
<html:option value="operator">operator</html:option>
<html:option value="admin">admin</html:option>
</html:select>
<script language="javascript">
function selectValue(){
alert(document.all.userRole.options[document.all.userRole.selectIndex].value);
}
</script>
2、radio标签的取值方法如下:
<html:radio property="userRole" value="operator" onclick="radioValue()"/>
<html:radio property="userRole" value="admin" onclick="radioValue()"/>
<script language="javascript">
function radioValue(){
var obj = document.all.userRole;
if(obj){
for(var i=0;i<obj.length;i++){//适合length>=2时,当obj.length==null时,可以直接取obj.value值
if(obj[i].checked){
alert(obj[i].value);
break;
}
}
}
}
</script>
- html:select、radio之六取值问题
- 【转】html:select、radio取值问题
- html:radio 之二--选中问题
- radio与select问题
- HTML select ,radio的使用,checkbox全选
- html自定义checkbox、radio、select —— checkbox、radio篇
- html之复选杜框(checkbox)、单选按钮(radio)、下拉菜单(select-option)
- Struts中 html:radio,html:multibox,html:select 使用实例
- html自定义checkbox、radio、select —— select篇
- html自定义checkbox、radio、select —— select篇
- html:radio之五使用方法
- javascript特效之radio控制select可用性
- JQuery之禁用radio、select、checkbox
- selenium自动化之radio,select,checkbox
- Jquery 操作Html 控件 CheckBox、Radio、Select 控件
- jQuery 操作 html 元素的例子 (input/select/checkbox/radio)
- Jquery 操作Html 控件 CheckBox、Radio、Select 控件
- Jquery 操作Html 控件 CheckBox、Radio、Select 控件
- html:radio之三默认选中
- 第一篇文章
- struts html:radio之四初始值与判断
- html:radio之五使用方法
- Fedora 10 取消某些分区的开机自动挂载
- html:select、radio之六取值问题
- Planning
- Fedora 10里将普通用户添加到sudo组
- C#设置word颜色
- Fedora 11 桌面去除windows分区显示
- 怎么改linux主机名?
- 嵌入式linux驱动开发入门总结
- Eclipse插件安装的三种方法
- 啥也不会