使用prototype.js选择选中radio与checkbox

来源:互联网 发布:淘宝外宣怎么宣传 编辑:程序博客网 时间:2024/05/18 14:14

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>使用prototype.js选择选中radio与checkbox by okajax.com</title>
<script language="javascript" type="text/javascript" src="prototype.js"></script>
<script language="javascript" type="text/javascript">

    function testSelect()   
    {   
        var chkbox = document.getElementsByName('slt');   
        var nodes = $A(chkbox);   
        var sltNodes = nodes.select(function(node)   
        {   
        return node.checked;   
        });   
        sltNodes.each(function(node)   
        {   
        alert(node.value);   
        });   
    }   


    function testSelect2() {   
       $$('input[type="radio"][name="bank"]').select(function(i){return i.checked}).each(function(i){alert(i.value)});   
    }   
</script>

</head>

<body>

<input type="checkbox" name="slt" value="1"/>
1<br/>

<input type="checkbox" name="slt" value="2"/>

2<br/>

<input type="checkbox" name="slt" value="3" checked="true"/>

3<br/>

<input type="button" value="test select" onclick="testSelect()">

 

<hr
/>

 

<input type="radio" name="bank" value="bank1"/>

1<br/>

<input type="radio" name="bank" value="bank2"/>

2<br/>

<input type="radio" name="bank" value="bank3" checked="true"/>

3<br/>

<input type="button" value="test select" onclick="testSelect2()">

 

</body>

</html>

原创粉丝点击