当前位置: 代码迷 >> Web前端 >> radio 动态取舍
  详细解决方案

radio 动态取舍

热度:515   发布时间:2012-11-10 10:48:50.0
radio 动态选择

(1) jsp 页面中的radio部分:
????? <div class="left">
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? 软件类型:
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? </div>
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? <div class="right">
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? <div class="radio_b">
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? <input name="softType" type="radio" value="fun" />
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? 娱乐
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? </div>
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? <div class="radio_b">
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? <input name="softType" type="radio" value="game" />
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? 游戏
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? </div>
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? <div class="radio_b">
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? <input name="softType" type="radio" value="chat" />
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? 聊天
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? </div>
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? <div class="radio_b">
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? <input name="softType" type="radio" value="other" />
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? 其他
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? </div>
??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? </div>
(2) 动态选择的JS


//<%=softInfo.getSoftType%> 为传递多来的参数
??? function getRadioValue(){
?????? var obj=document.getElementsByName("softType")
???? for(var i=0;i<obj.length;i++){

??????? if(obj[i].value==<%=softInfo.getSoftType%>){

??????????? obj[i].checked=true;

??????????? break;

}

}

}

?

(3) 页面加载的时候自动执行js

在body 属性中添加:onload="getRadioValue()"

如:<body onload="getRadioValue()">

?

?

? .....

??? </body>

?

  相关解决方案