zoukankan      html  css  js  c++  java
  • radio默认值

    Html代码
    <html:radio property="consumptionClass" value="花了" >花了</html:radio>  
    <html:radio property="consumptionClass" value="赚了" >赚了</html:radio>  
    <html:radio property="consumptionClass" value="借出" >借出</html:radio>  
    <html:radio property="consumptionClass" value="借入" >借入</html:radio>  

    方法1

    在jsp页面最后面加入

    Js代码 
    <script>     
      
    alert("${consumptionClass}");   
      
    if("${consumptionClass}" == "花了")   
    {   
        document.all("consumptionClass")[0].checked=true;//第一个radio选中   
    }     
    if("${consumptionClass}" == "赚了")   
    {   
        document.all("consumptionClass")[1].checked=true;//第二个radio选中   
    }   
    if("${consumptionClass}" == "借出")   
    {   
        document.all("consumptionClass")[2].checked=true;//第三个radio选中   
    }   
    if("${consumptionClass}" == "借入")   
    {   
        document.all("consumptionClass")[3].checked=true;//第四个radio选中   
    }   
    </script>   



    方法2

    要让<html:radio>选择很关键的一点,就是,这个JSP势必对应的一个actionform吧,给它个初始值就OK了

    默认值是动态的话

    请注意到name属性

    性别

    Html代码
    <html:radio value="花了" property="consumptionClass" name="cco">花了</html:radio>     
    <html:radio value="赚了" property="consumptionClass" name="cco">赚了</html:radio>     
    <html:radio value="借出" property="consumptionClass" name="cco">借出</html:radio>     
    <html:radio value="借入" property="consumptionClass" name="cco">借入</html:radio>    

    只要在request,session等范围内存在user,这个上面的标签就会根据consumptionClass.cco的值产生默认选中了

    <html>  
        <head>  
            <title>初始化单选</title>  
            <script>  
                function initradio(rName,rValue){  
                    var rObj = document.getElementsByName(rName);  
     
                    for(var i = 0;i < rObj.length;i++){  
                        if(rObj[i].value == rValue){  
                            rObj[i].checked =  'checked';  
                        }  
                    }  
                }  
            </script>  
        </head>  
        <body>  
            <form action="#"><input type="radio" name="tRadio" value="1"><input type="radio" name="tRadio" value="2"><input type="radio" name="tRadio" value="3"><input type="radio" name="tRadio" value="4">  
            </form>  
            <script>  
                initradio('tRadio',3);  
            </script>  
        </body>  
    </html> 
    <%@page pageEncoding="gbk"%>
    <html>
        <head>
            <title>Index</title>
            <script type="text/javascript">
                function initradio(name,value){
                    var r1=document.getElementsByName(name);
                    for(var i=0;i<r1.length;i++){
                        if(r1[i].value==value){
                            r1[i].checked=true;
                        }
                    }
                }
            </script>
        </head>
        <body onload="initradio('r','<%=request.getParameter("value") %>')">
            <center>
                <h1>Index</h1>
                <hr>
                <p>请选择:</p>
                <input type="radio" name="r" value="A">A
                <br>
                <input type="radio" name="r" value="B">B
                <br>
                <input type="radio" name="r" value="C">C
                <br>
                <input type="radio" name="r" value="D">D
                <br>
            </center>
        </body>
    </html>


     

     

  • 相关阅读:
    C++第7周任务3输出星号图详解示例
    C++第7周任务3输出星号图全解
    C02程序设计基础提高班(C++)第7周上机任务指针
    毕业生反馈(三)
    C++程序设计第七周上机实践项目
    C03Java同步实践加强班第7周上机任务
    写给菜鸟:发CSDN博文常见问题处理
    android项目 添加
    编译某一个ko模块make modules SUBDIRS=drivers/xxx/
    修改其他输入法为android 默认输入法
  • 原文地址:https://www.cnblogs.com/mingforyou/p/2200829.html
Copyright © 2011-2022 走看看