jsp radio value and assignment

Reprinted from: https://blog.csdn.net/dongfengkuayue/article/details/50352937

Take the value of radio:

js code

  $("input[name='radioName'][checked]").val(); 

Assign a value to radio and select the radio with a value of 2:

js code:

  $("input[name='radioName'][value=2]").attr("checked",true); 

<script type="text/javascript">  
    $(document).ready(function(){  
        var type=<%=(String)request.getAttribute("specialType")%>;  
        if(type==0){  
            $("input[name='specialType'][value=0]").attr("checked",true);   
        }else{  
            $("input[name='specialType'][value=1]").attr("checked",true);  
        }   
    });  
</script>  

 

<table>
    <tr>
        <td class="td_label">Special Type</td>
        <td>
            <label for="whiteList">Whitelist</label>
            <input type="radio" id="specialType1" name="specialType" value="0"/>
            <label for="blackList">Blacklist</label>
            <input type="radio" id="specialType2" name="specialType" value="1" />
        </td>
    </tr>
</table>

 

Also: https://blog.csdn.net/zbyluxzing/article/details/46965915

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324776319&siteId=291194637