ورود

View Full Version : سرچ در ستون hidden یک جدول توسط js



resident
پنج شنبه 27 اسفند 1394, 01:07 صبح
سلام.
من میخوام روی دومین ستون hidden از جدول زیر که نامش InvoiceItems[x].Id هست سرچ کنم . اگه مقدار اون ستون برابر 2 بود یه alert برگزدونم.

چطور این کار باید انجام بشه؟

<table class="table table-striped table-hover" id="Invoicedt">
<thead>
<tr>
<th>
ردیف
</th>
<th>
نام
</th>
</tr>
</thead>
<tbody>
<tr>
<input type="hidden" value="0" name="InvoiceItems.Index"/>
<input type="hidden" value="" name="InvoiceItems[0].Id"/>

<td>5</td>
<td>xxx</td>
</tr>
<tr>
<input type="hidden" value="1" name="InvoiceItems.Index"/>
<input type="hidden" value="" name="InvoiceItems[1].Id"/>
<td>2</td>
<td>yyy</td>
</tr>
<tr>
<input type="hidden" value="3" name="InvoiceItems.Index"/>
<input type="hidden" value="" name="InvoiceItems[3].Id"/>
<td>3</td>
<td>zzz</td>
</tr>
</tbody>
</table>

blue.web9
پنج شنبه 27 اسفند 1394, 17:40 عصر
داخل هر سطر مقدار دومین input میگیریم و بررسی میکنیم.


$(document).ready(function (){
$('#Invoicedt > tbody > tr').each(function (){
var value = $( 'input:eq( 1 )', this ).val();
if( value === 2 )
{
alert( value );
}
});
});

resident
جمعه 28 اسفند 1394, 02:36 صبح
داخل هر سطر مقدار دومین input میگیریم و بررسی میکنیم.


$(document).ready(function (){
$('#Invoicedt > tbody > tr').each(function (){
var value = $( 'input:eq( 1 )', this ).val();
if( value === 2 )
{
alert( value );
}
});
});


blue.web9 جان ممنون از وقتی که گذاشتی.
نمیشه بر اساس نام input سرچ کرد؟ چون ممکنه ستونها جابجا بشن و همیشه ستون دوم اون فیلد نباشه

milad_d993
جمعه 28 اسفند 1394, 04:42 صبح
برای input های مورد نظر یه کلاس به نام مثلا search بزار
درضمن برای اینکه بر اساس input جستجو بکنه باید value داشته باشه که تو کد شما value = "" هست؛ توی کد جدید مقدار ستون اول رو بعنوان مقدار input قرار دادم.


<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function (){
$('.search').each(function (){
if($(this).val() == 2){
$(this).parent().css({"color": "red", "border": "2px solid red"});
alert("found...");
}
});
});
</script>
</head>
<body>
<table class="table table-striped table-hover" id="Invoicedt">
<thead>
<tr>
<th>ردیف</th>
<th>نام</th>
</tr>
</thead>
<tbody>
<tr>
<input type="hidden" value="0" name="InvoiceItems.Index" style="ba"/>
<input type="hidden" value="5" name="InvoiceItems[0].Id" class="search"/>
<td>5</td>
<td>xxx</td>
</tr>
<tr>
<input type="hidden" value="1" name="InvoiceItems.Index"/>
<input type="hidden" value="2" name="InvoiceItems[1].Id" class="search"/>
<td>2</td>
<td>yyy</td>
</tr>
<tr>
<input type="hidden" value="3" name="InvoiceItems.Index"/>
<input type="hidden" value="3" name="InvoiceItems[3].Id" class="search"/>
<td>3</td>
<td>zzz</td>
</tr>
</tbody>
</table>
</body>
</html>

blue.web9
شنبه 29 اسفند 1394, 08:30 صبح
حالا براساس name سلکت میکنه و هر نامی به این صورت InvoiceItems[ شروع بشه بررسی میشه



$(document).ready(function (){
$('#Invoicedt > tbody > tr').each(function (){
$('input[name^="InvoiceItems["]' , this).each(function (){
var value = $(this).val();
if( value == 2 )
{
alert( value );
}
});
});
});