日期:2014-05-16 浏览次数:20476 次
<td class="td_right"> <select id="p1" onchange="Unions(this.id,this.parent);" parent=""> <option selected="selected" value="a">a</option> </select> </td> <td class="td_right"> <select id="p2" onchange="Unions(this.id,this.parent);" parent="p1"> <option selected="selected" value="b">b</option> </select> </td> <td class="td_right"> <select id="p3" onchange="Unions(this.id,this.parent);" parent="p2"> <option selected="selected" value="c">c</option> </select> </td>
<!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=utf-8" /> <title>无标题文档</title> <script type="text/javascript"> function Unions(parentID) { var result = []; parentID = document.getElementById(parentID).getAttribute('parent'); while (parentID != '') { result.push(document.getElementById(parentID).value); parentID = document.getElementById(parentID).getAttribute('parent'); } alert(result.reverse()); } </script> </head> <body> <table> <tr> <td class="td_right"><select id="p1" onclick="Unions(this.id,this.parent);" parent=""> <option selected="selected" value="a">a</option> </select></td> <td class="td_right"><select id="p2" onclick="Unions(this.id,this.parent);" parent="p1"> <option selected="selected" value="b">b</option> </select></td> <td class="td_right"><select id="p3" onclick="Unions(this.id,this.parent);" parent="p2"> <option selected="selected" value="c">c</option> </select></td> </tr> </table> </body> </html>
------解决方案--------------------
更正一下。。
<!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=utf-8" /> <title>无标题文档</title> <script type="text/javascript"> function Unions(parentID) { var result = []; if (parentID == '') return false; while (parentID != '') { result.push(document.getElementById(parentID).value); parentID = document.getElementById(parentID).getAttribute('parent'); } alert(result.reverse()); } </script> </head> <body> <table> <tr> <td class="td_right"><select id="p1" onclick="Unions(this.getAttribute('parent'));" parent=""> <option selected="selected" value="a">a</option>