日期:2014-05-16  浏览次数:20507 次

怎么向上级元素在向下找到自己想要的元素的text值并打印
JScript code
<html>
    <head>
        <script type="text/javascript">
            function window_onload()
            {
                for(var i=0;i<document.forms[0].option.length;i++)
                {
                    if(document.forms[0].option[i].checked)
                    {
                        var temp = document.forms[0].option[i].value;
                        alert(temp);
                        var team = document.forms[0].option[i];
                        var text = team.parent('td').parent('tr').find('td').eq(1).text();
                        alert(text);
                    }
                }
            }
        </script>
    </head>
        <form method="post" name="form_gotopage" >
            <div id="menuBarContainer">
            </div>
            <table id="report_table" border=1 cellspacing=0 cellpadding=0>
                <thead>
                <tr>
                    <th width="15" style="padding-left:3px;"><input type="checkbox"  id="option"></th>
                    <th>test</th>
                    <th>tkkkkk</th>
                    <th>yyyyy</th>
                </tr>
                </thead>
                <tr>
                    <td align="center"><input type="checkbox" name="id[]"  id="option" value="1 line and 1 column "></td>
                    <td>hello</td>
                    <td>word</td>
                    <td>good</td>
                </tr>
                <tr>
                    <td align="center"><input type="checkbox" name="id[]"  id="option" value="2 line and 2 column "></td>
                    <td>hello2</td>
                    <td>word2</td>
                    <td>good2</td>
                </tr>
            </table>
        </form>
        <input type='button' value='clicke me' onclick='return window_onload()'>
    </body>
</html>


我想通过那onclick函数返回我选的那一行的地2个td的text值,怎么整都整不出来,请高手赐教

------解决方案--------------------
JScript code
<script type="text/javascript">
            function window_onload()
            {
                alert($("input:checked").parent().siblings().text());
            }
</script>

------解决方案--------------------
探讨

JScript code
<script type="text/javascript">
function window_onload()
{
alert($("input:checked").parent().siblings().text());
}
</script>

------解决方案--------------------
看一下JS的DOM文章吧 就那么几个方法 
弄懂了 在用jQuery
------解决方案--------------------
JScript code

function window_onload()
{   
    for(var i=0;i<document.forms[0].option.length;i++)
    {
        if(document.forms[0].option[i].checked)
        {
            var temp = document.forms[0].option[i].value;
            //alert(temp);
            var team = document.forms[0].option[i];
            
            var text = "";
            var tr = team.parentNode.parentNode;//得到TR
            var tds = tr.childNodes;
            var flag = 0;
            for(var j=0; j< tds.length;j++){