【转】html:select、radio取值问题
来源:互联网 发布:jenkins 插件源码下载 编辑:程序博客网 时间:2024/05/21 17:02
一、页面加载时初始值问题:
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取值问题
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中 (转别人的)
- html一些取值radio
- html:select、radio之六取值问题
- jquery radio取值,checkbox取值,select取值
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
- 【jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中】
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
- JQuery radio,select选中与取值
- Jquery取值简介(radio,select,checkbox)
- radio select 等各种取值
- jquery 取值 radio 问题
- jquery radio取值,checkbox取值,select取值,radio选中值
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中
- jquery radio取值,checkbox取值,select取值,radio选中
- JDBC连接Mysql , sql server ,oracle 的方法
- 想回校
- Endian的由来(转载)
- 翻译:Panda3D Manual/V. Programming with Panda/D. Actors and Characters
- 翻译:Panda3D Manual/V. Programming with Panda/E. Camera Control
- 【转】html:select、radio取值问题
- 翻译:Panda3D Manual/V. Programming with Panda/F. Sound
- 翻译:Panda3D Manual/V. Programming with Panda/G. Intervals
- div+css 布局
- 翻译:Panda3D Manual/V. Programming with Panda/H. Tasks and Event Handling
- 5 Most Common Web Standards Misconceptions
- 翻译:Panda3D Manual/V. Programming with Panda/I. Fog and Lighting
- 关于HTML,input radio的奇怪问题。
- 翻译:Panda3D Manual/V. Programming with Panda/J. Text and Image Rendering