gpt4 book ai didi

javascript - 单击同一行中的 anchor 标记,从表中选择同一行中的输入标记

转载 作者:行者123 更新时间:2023-11-29 18:22:56 25 4
gpt4 key购买 nike

示例 Html(这只包含更多行中的一个)。

<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>

我的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");
});
});

我想做的是在同一行 tr 中选择输入标签,但在同一行中单击 anchor 标签时选择不同的 td 。我尝试了以下 jQuery 语句的多种组合,但均未成功。请帮忙。$(this).parent().parent().children('td input').text() 这里的this代表被点击的 anchor 标签。更清楚地说,我不想选择表中的所有输入标签,只选择同一行中的那些。

最佳答案

使用 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()find()

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

使用上下文

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

working fiddle here

关于javascript - 单击同一行中的 anchor 标记,从表中选择同一行中的输入标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16557895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com