在jQuery中选择属性的值 [英] Select the value of an attribute in jQuery

查看:225
本文介绍了在jQuery中选择属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下表:

<table summary='' id='table_csrdownloadcenter'>
<thead>
<tr>
<th>text1</th>
<th>text2</th>      
<th>text3</th>
<th>text4</th>
<th>text5</th>
<th>text6</th>
<th>text7</th>
<th>text8</th>
</tr>
</thead>
<tbody> 

<tr id='nom_du_pdf'>
<td class='dc-date'></td>
<td class='dc-dl'></td>                                             
<td class='dc-title'></td>
<td class='dc-area'></td>
<td class='dc-category'></td>
<td class='dc-file'></td>
<td class='dc-ranking'></td>
<td class='dc-checkbox'><input type='checkbox' name='chk"+PathFile[i]+"' ></td>
</tr>

<tr id='nom_du_pdf2'>
<td class='dc-date'></td>
<td class='dc-dl'></td>                                             
<td class='dc-title'></td>
<td class='dc-area'></td>
<td class='dc-category'></td>
<td class='dc-file'></td>
<td class='dc-ranking'></td>
<td class='dc-checkbox'><input type='checkbox' name='chk"+PathFile[i]+"' ></td>
</tr>


</tbody>
<table>

每个 < tr> 我想在字符串中保存第8个< td>
中name属性的值我试过这个:

For each <tr> I would like to save in a string the value of the name attribute in the 8th <td> I tried this :

function DownloadZip()
{
$('.DownloadZip').click(function(){

        var res = "";
    $('#table_csrdownloadcenter').find("tbody").find("tr").find(td:nth-child(8)).find("input").each(function(){
       res = $(this).attr("name").text();
       alert(res);
    }
});
}

任何人都可以帮我完成这项工作吗? / p>

Can anyone help me to make this working?

推荐答案

迭代每个 tr ,然后检查 8th td的输入

Iterate each tr, then check the 8th td's input

var mappedAttributes = $("#table_csrdownloadcenter tr").map(function() {
    return $("td:eq(7) input", this).attr("name");
}).get();

这会创建一个数组每个名称属性值。

This creates an array of each of the name attribute values.

创建字符串:

var str = "";
$("#table_csrdownloadcenter tr").each(function() {
    str += $("td:eq(7) input", this).attr("name");
})

这篇关于在jQuery中选择属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆