开发者

Getting a value of td of a selected tr in jquery

开发者 https://www.devze.com 2023-01-01 06:42 出处:网络
Below is my table <table> <tr class=chargeTR> <td id=chargeTD> charge1 </td> </tr class=chargeTR>

Below is my table

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

Below is my jQuery call

$(".chargeTR").each(function() { // this line works fine
        $.get("process.php", {
            va开发者_如何学JAVAlue: $(this).find("#chargeTD").val(), // I must be doing something wrong here...
        }, function(theXML){
            alert(theXML);
        });
});

I cannot get the value "charge1" and "charge2".

Can somebody please correct me in this?


use .text() or .html() instead of .val(), since .val is intended to get value="" attributes from forms.


You may also need to use $.trim() to get exact text without whitespace.

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


It worked form me:

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());
    }); 
});
0

精彩评论

暂无评论...
验证码 换一张
取 消