小弟我想点击一上按钮后,表格中 tr id为6的2个 td 里边的值分别付给 text

我想点击一下按钮后,表格中 tr id为6的2个 td 里边的值分别付给 text本帖最后由 wrost 于 2013-01-23 09:2

我想点击一下按钮后,表格中 tr id为6的2个 td 里边的值分别付给 text
本帖最后由 wrost 于 2013-01-23 09:23:16 编辑 我想点击一下按钮后,表格中 tr id为6的2个 td 里边的值分别付给 text

我现在写的没有function Info()效果


<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
        function displayInfo() {$("#Name").val("test");
      
        }
function Info()

var y=$("#6").cells[1].innerHTML; 
var x=$("#6").cells[1].innerHTML; 
$("#ID").val(y)
$("#Name").val(x)
}
</script>
</head>

<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button onclick="Info()" type="button">Click me</button>
<table width="100%">
             <tr id="6" onmouseover="displayInfo()">
                <td>6
                </td>
                <td>高考文库
                </td>
</tr>
             <tr id="7" onmouseover="displayInfo()">
                <td>7
                </td>
                <td>中考文库
                </td>
            </tr>
<table/>
<br/>
<p>数字<input class="textbox" id="ID" name="Name" type="text" value="" /></P>
文库<input class="textbox" id="Name" name="Name" type="text" value="" />
</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" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function displayInfo() {
            $("#Name").val("test");
        }
        function Info() {
            var y = $("#6 >td:eq(0)").html();


            var x = $("#6 >td:eq(1)").html();
            $("#ID").val(y)
            $("#Name").val(x)
        }
    </script>
</head>
<body>
    <h2>
        This is a heading</h2>
    <p>
        This is a paragraph.</p>
    <p>
        This is another paragraph.</p>
    <button onclick="Info()" type="button">
        Click me</button>
    <table width="100%">
        <tr id="6" onmouseover="displayInfo()">
            <td>
                6
            </td>
            <td>
                高考文库
            </td>
        </tr>
        <tr id="7" onmouseover="displayInfo()">
            <td>
                7
            </td>
            <td>
                中考文库
            </td>
        </tr>
    </table>
    <br />
    <p>
        数字<input class="textbox" id="ID" name="Name" type="text" value="" /></p>
    文库<input class="textbox" id="Name" name="Name" type="text" value="" />
</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" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function displayInfo() {
            $("#Name").val("test");
        }
        function Info(i) {


            var y = $("#" + i + " >td:eq(0)").html();
            var x = $("#" + i + " >td:eq(1)").html();
            $("#ID").val(y)
            $("#Name").val(x)
        }
    </script>
</head>
<body>
    <h2>
        This is a heading</h2>
    <p>
        This is a paragraph.</p>
    <p>
        This is another paragraph.</p>
    <button onclick="Info(6)" type="button">
        Click me ( For first row ) </button>
    <button onclick="Info(7)" type="button">
        Click me ( For Second row  )</button>
    <table width="100%">
        <tr id="6" onmouseover="displayInfo()">
            <td>
                6
            </td>
            <td>
                高考文库
            </td>
        </tr>
        <tr id="7" onmouseover="displayInfo()">
            <td>
                7
            </td>
            <td>
                中考文库
            </td>
        </tr>
    </table>
    <br />
    <p>
        数字<input class="textbox" id="ID" name="Name" type="text" value="" /></p>
    文库<input class="textbox" id="Name" name="Name" type="text" value="" />
</body>
</html>