教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 js实现radio和select的默认选中

js实现radio和select的默认选中

发布时间:2014-11-25   编辑:jiaochengji.com
本文介绍下,用javascript实现raido与select的默认选中的方法,通过具体的实例,帮助大家理解,有需要的朋友参考下吧。

1、radio默认选中的js代码,其中<%=order.getType()%>为后台数据。
 

复制代码 代码示例:
<script>
//radio默认选中
 function init(){
  var v = '<%=order.getType()%>';
  var type = document.getElementsByName("orderType");
  for(var i = 0; i < type.length; i = i + 1){
  if(type[i].value == v){
  type[i].checked = "checked";
  return ;
  }
  }
 }
</script>

2、select默认选中的js代码,其中<%=order.getType()%>为后台数据。
 

复制代码 代码示例:
<script>
//select默认选中
//by www.jiaochengji.com
function init(){
  var v = '<%=c.getLevel()%>';
  var type = document.getElementById("level");
  for(i = 0;i<=type.options.length;i++){
if(type.options[i].value == v){
type.options[i].selected = 'selected';
}
}
 }
</script>

3、调用示例
 

<body onload="init();">

您可能感兴趣的文章:

关键词: radio  select  默认选中   
[关闭]
~ ~