首先,Radiolist控件默认Render后最外面是个<table>,好,看代码,传统方式:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
2
3 transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
5
6 <head>
7 <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
8 <title>test</title>
9 <script type="text/javascript">
10 function test2()
11 {
12 var rbltable = document.getElementById("rl");
13 var rbs= rbltable.getElementsByTagName("INPUT");
14 for(var i = 0;i<rbs.length;i++)
15 {
16 if(rbs[i].checked)
17 {
18 var value=rbs[i].value;
19 alert(value);
20 //Js_open(b)
21 }
22 else
23 {
24 //Js_open(a)
25 }
26 }
27 }
28
29 </script>
30 </head>
31
32 <body>
33
34 <form>
35 <span id="dd"></span>
36 <table id="rl">
37 <tr>
38 <td><label>收</label><input id="rl_1" checked="checked" name="rl$tt" type="radio" value="1" />
39 <label>发</label><input id="rl_2" name="rl$tt" type="radio" value="2" />
40 </td>
41 </tr>
42 </table>
43 <input name="b1" onclick="test2();" type="button" value="确定" />
44 </form>
45
46 </body>
47
48 </html>
49
2
3 transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
5
6 <head>
7 <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
8 <title>test</title>
9 <script type="text/javascript">
10 function test2()
11 {
12 var rbltable = document.getElementById("rl");
13 var rbs= rbltable.getElementsByTagName("INPUT");
14 for(var i = 0;i<rbs.length;i++)
15 {
16 if(rbs[i].checked)
17 {
18 var value=rbs[i].value;
19 alert(value);
20 //Js_open(b)
21 }
22 else
23 {
24 //Js_open(a)
25 }
26 }
27 }
28
29 </script>
30 </head>
31
32 <body>
33
34 <form>
35 <span id="dd"></span>
36 <table id="rl">
37 <tr>
38 <td><label>收</label><input id="rl_1" checked="checked" name="rl$tt" type="radio" value="1" />
39 <label>发</label><input id="rl_2" name="rl$tt" type="radio" value="2" />
40 </td>
41 </tr>
42 </table>
43 <input name="b1" onclick="test2();" type="button" value="确定" />
44 </form>
45
46 </body>
47
48 </html>
49
再看下JQuery,如何实现,非常简单:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
3 <html xmlns="http://www.w3.org/1999/xhtml" >
4 <head runat="server">
5 <title>test</title>
6 <script src="js/jquery-1.2.6-intellisense.js" type="text/javascript"></script>
7 <script type="text/javascript">
8 function GetJump() {
9 var $selectedvalue = $("input[name='rl$tt']:checked").val();
10 alert($selectedvalue);
11 if ($selectedvalue == 1) {
12 window.location = "http://www.g.cn";
13 }
14 else {
15 window.location = "http://www.baidu.com";
16 }
17 }
18 </script>
19 </head>
20 <body>
21 <form id="form1" runat="server">
22 <table id="rl">
23 <tr>
24 <td><label>谷歌</label><input id="rl_1" checked="checked" name="rl$tt" type="radio" value="1" />
25 <label>百度</label><input id="rl_2" name="rl$tt" type="radio" value="2" />
26 </td>
27 </tr>
28 </table>
29 <input type="button" id="btn1" value="确定" onclick="GetJump()" />
30 </form>
31 </body>
32 </html>
2
3 <html xmlns="http://www.w3.org/1999/xhtml" >
4 <head runat="server">
5 <title>test</title>
6 <script src="js/jquery-1.2.6-intellisense.js" type="text/javascript"></script>
7 <script type="text/javascript">
8 function GetJump() {
9 var $selectedvalue = $("input[name='rl$tt']:checked").val();
10 alert($selectedvalue);
11 if ($selectedvalue == 1) {
12 window.location = "http://www.g.cn";
13 }
14 else {
15 window.location = "http://www.baidu.com";
16 }
17 }
18 </script>
19 </head>
20 <body>
21 <form id="form1" runat="server">
22 <table id="rl">
23 <tr>
24 <td><label>谷歌</label><input id="rl_1" checked="checked" name="rl$tt" type="radio" value="1" />
25 <label>百度</label><input id="rl_2" name="rl$tt" type="radio" value="2" />
26 </td>
27 </tr>
28 </table>
29 <input type="button" id="btn1" value="确定" onclick="GetJump()" />
30 </form>
31 </body>
32 </html>