获得table某个单元格的内容,然后将select中等于该内容的项,变为选中项。

var tds=$('#infor tr:eq(1) td:nth-child(7)').html();
$("#seachContinent").find("option[text='"+tds+"']").attr("selected",true);
tds可以获得内容,第二行中的tds若写死为“非洲”也是好用的,但是上面的这样写就不好用,请问问题出在哪里?

是不是有空格什么的。自己用jquery的trim方法去掉下首位空格

     var tds = $.trim($('#infor tr:eq(1) td:nth-child(7)').html());

把第一行中的html()方法改为text()方法试试。

var tds=$('#infor tr:eq(1) td:nth-child(7)').html();
为什么要获取html?你alert一下tds是你想要的吗?不会带尖括号什么的吗?
你试试换成.text();

我这个试验过了,完全可以,你参考一下。

 <html>
<head>
    <script src="jquery-1.4.2.js"></script>
    <script type="text/javascript">
        $(function(){
            var tds = $("#table01 tr:eq(2) td:eq(2)").html();
            alert($("#select01").find("option[text='"+tds+"']").text());
            $("#select01").find("option[text='"+tds+"']").attr("selected",true);
        })
    </script>
</head>
<body>
    <div>
        <table cellspacing="0" cellpadding="0" border="1" id="table01">
            <tr>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
            </tr>
            <tr>
                <td>张三</td>
                <td>30</td>
                <td>男</td>
            </tr>
            <tr>
                <td>李四</td>
                <td>25</td>
                <td>女</td>
            </tr>
        </table>

        <select id="select01">
            <option selected="true">请选择性别</option>
            <option>男</option>
            <option>女</option>
            <option>不男不女</option>
        </select>
    </div>
</body>
</html>