2

Sample Html(This only contains one of many more row).

<table id="ctl00_ContentPlaceHolder1_categoryTable" class="categoryTable sortAsc editInputs" border="0">
    <tbody>
     <tr>
     <td>8</td>
     <td>
     <input name="ctl00$ContentPlaceHolder1$ctl17" type="text" value="307349_335692806541952_16061425_n.jpg" readonly="readonly" />
    </td>
    <td><input name="ctl00$ContentPlaceHolder1$ctl18" type="text" value="key1 " readonly="readonly" /></td>
    <td>3/28/2013</td>
    <td>.jpg</td>
    <td>28120</td>
    <td><a href="download.aspx filename=307349_335692806541952_16061425_n.jpg&type=image">307349_335692806541952_16061425_n.jpg</a></td>
    <td>
    <a href="javascript:void(0)" class="editLinkClass">Edit </a><a href="javascript:void(0)" class="deletetLinkClass"> Delete</a><a href="javascript:void(0)" class="updateLinkClass" style="display:none;">Update</a><a href="javascript:void(0)" class="cancelLinkClass" style="display:none;"> Cancel</a>
    </td>
    <tr>
    </tbody>

My Javascript

$(document).ready(function () {
            console.log("document ready")
            $(".categoryTable tr td a").click (function (event) {
                console.log($(this).text() + "click detected");
                if ($(this).text() === "Edit ") {//compare with "Edit " not "Edit"
                    console.log("Edit");
                    console.log($(this).parent().parent().children('td input').text());
                    $(this).siblings(".deletetLinkClass").attr("style", "display:none");
                    $(this).siblings(".updateLinkClass").attr("style", "display:;");
                    $(this).siblings(".cancelLinkClass").attr("style", "display:;");
                    $(this).attr("style", "display:none")
                }
                else
                    console.log("no EDit");
            });
        });

What i am trying to do is select the input tags in the same row tr but different td on click of an anchor tag in the same row. I have tried a lot of combinations of the following jQuery statement with no success. Please Help. $(this).parent().parent().children('td input').text() Here this represents the clicked anchor tag. To be more clear i don't want to select all the input tags in the table, just the ones in the same row.

4

3 回答 3

2

你可以这样做:

$('td input', $(this).closest('tr')).val();
于 2013-05-15T06:16:00.597 回答
2

使用parents()find()

并获得输入的价值,使用val()而不是text()..

$(this).parent().parent().children('td input').text();
                                           //--^^^^^^---here  

尝试这个

var inputs=$(this).parents('tr').find('input');
$.each(inputs,function(){  //<---- loop since you have multiple input
    console.log($(this).val()); //.val() since val() is used to get the input value..
})

或使用closest()and find()

var inputs=$(this).closest('tr').find('input');

使用上下文

var inputs = $('td input', $(this).closest('tr')).val();

在这里工作小提琴

于 2013-05-15T06:04:34.690 回答
0

尝试下面的代码来查找给定行的输入

$(this).closest('tr').find('td input').text()
于 2013-05-15T06:05:22.577 回答