---
title: "JavaScript:radio object:实例1"
author: "ilusm"
date: "2008-06-13T16:04:19Z"
tags: []
slug: "javascript-radio-object-1"
draft: false
lastmod: "2008-06-13T16:04:19Z"
id: 232238
url: "https://ilusm.iteye.com/blog/232238"
---

当然还可以用DWRUtil.getValue("selHotel");取值。在只有一个radio时，那么document.frm.selHotel.checked 值为true或flase，DWRUtil.getValue("selHotel")的值为true或flase，radio的值为document.frm.selHotel.value即true或flase。如果有多个radio时，那么document.frm.selHotel\[i].checked 值为true或flase，DWRUtil.getValue("selHotel")的值为document.frm.selHotel\[i].value，radio的值为document.frm.selHotel\[i].value。

```
<script language="javascript">
function selHotel()
{
    var HotelCode ="";  
    var intValid = document.frm.selHotel.length;  
    if(document.frm.selHotel.checked == true )  
    {   
        HotelCode = document.frm.selHotel.value;  }     
	if(intValid >1){     
	    for(var i =0;i<document.frm.selHotel.length;i++){
	    //alert(document.frm.selHotel[i].checked);      
	    if (document.frm.selHotel[i].checked== true ){       
		HotelCode = document.frm.selHotel[i].value;       
		//alert(HotelCode);      
		}     
	    }    
	}
    }
</script>
 <form name="frm" action="">
<input type="radio" name ="selHotel' value="1">
<input type="radio" name="selHotel" value="2">
</form>
```