如何获取每个 table 行中的隐藏字段值
How to get the hidden field value in each table row
i just want to get the hidden field value in each row of the table,how
can i do this,any suggestions appreciated
这是一个使用数组的简单示例。您只想获取隐藏的输入值并将其推入数组。
//create hidden fields array
var hiddenFields = [];
//for each table row
$("#yourTable tr").each(function()
{
//get hidden field value
var hiddenField = $(this).find("input[type='hidden']").val();
//if not empty push to array
if(hiddenField !='undefined'&& hiddenField !=null )
hiddenFields.push(hiddenField);
});
//output all hidden field values stored in array
console.log(hiddenFields);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="yourTable">
<tr><th>row id</th><th>column 1</th><th>column 2</th></tr>
<tr>
<td><input type="hidden" value="row id 1"> 1
</td><td>row 1</td><td>row 1</td>
</tr>
<tr>
<td><input type="hidden" value="row id 2"> 2
</td><td>row 2</td><td>row 2</td>
</tr>
<tr>
<td><input type="hidden" value="row id 3"> 3
</td><td>row 3</td><td>row 3</td>
</tr>
</table>
function ApplyProcessingColor()
{
$("#xhtml_grid tr").each(function()
{
var hdnLock=$(this).find("td:first").text();
if(hdnLock=='True')
{
$(this).css('background-Color','#7FFFD4');
}
});
}
通过这种方式我找到了解决方案
i just want to get the hidden field value in each row of the table,how can i do this,any suggestions appreciated
这是一个使用数组的简单示例。您只想获取隐藏的输入值并将其推入数组。
//create hidden fields array
var hiddenFields = [];
//for each table row
$("#yourTable tr").each(function()
{
//get hidden field value
var hiddenField = $(this).find("input[type='hidden']").val();
//if not empty push to array
if(hiddenField !='undefined'&& hiddenField !=null )
hiddenFields.push(hiddenField);
});
//output all hidden field values stored in array
console.log(hiddenFields);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="yourTable">
<tr><th>row id</th><th>column 1</th><th>column 2</th></tr>
<tr>
<td><input type="hidden" value="row id 1"> 1
</td><td>row 1</td><td>row 1</td>
</tr>
<tr>
<td><input type="hidden" value="row id 2"> 2
</td><td>row 2</td><td>row 2</td>
</tr>
<tr>
<td><input type="hidden" value="row id 3"> 3
</td><td>row 3</td><td>row 3</td>
</tr>
</table>
function ApplyProcessingColor()
{
$("#xhtml_grid tr").each(function()
{
var hdnLock=$(this).find("td:first").text();
if(hdnLock=='True')
{
$(this).css('background-Color','#7FFFD4');
}
});
}
通过这种方式我找到了解决方案