在jquery中获取所选tr的td值

时间:2010-05-24 03:37:16

标签: jquery html

以下是我的表

<table>
    <tr class=chargeTR>
        <td id=chargeTD>
            charge1
        </td>
    </tr class=chargeTR>
        <td id=chargeTD>
            charge2
        </td>
    </tr>
<table>

下面是我的jQuery调用

$(".chargeTR").each(function() { // this line works fine
        $.get("process.php", {
            value: $(this).find("#chargeTD").val(), // I must be doing something wrong here...
        }, function(theXML){
            alert(theXML);
        });
});

我无法获得值“charge1”和“charge2”。

请问有人可以纠正我吗?

3 个答案:

答案 0 :(得分:10)

使用.text().html()代替.val(),因为.val旨在从表单中获取value=""属性。

答案 1 :(得分:1)

您可能还需要使用$ .trim()来获取没有空格的精确文本。

$.trim($(this).find("#chargeTD").text())

答案 2 :(得分:0)

它起作用了我:

HTML:

<tr class="" id="tr_id" >
    <td class="l_id">7283630222</td>
</tr>
<tr class="" id="tr_id" >
    <td class="l_id">7276684022</td>
</tr>
<p id="leadID">-lead id here-</p>

jQuery的:

$(document).ready(function() {
    $("tr#tr_id").click(function() {
        $("#leadID").text($(this).find("td.l_id").text());
    }); 
});
相关问题