I have multiple textboxes with same class and different different id's. I want to apply two search criteria in for each loop. For example, I have these text fields:-
我有多个具有相同类和不同ID的文本框。我想为每个循环应用两个搜索条件。例如,我有这些文本字段: -
<input type="text" id="grid_5_collect_businame" class="search_ ui-autocomplete-input" style="width:100%;" value="" autocomplete="off">
<input type="text" id="grid_5_client_businame" class="search_" style="width:100%;" value="">
<input type="text" id="grid_5_collnurs" class="search_" style="width:100%;" value="">
<input type="text" id="grid_6_collect_businame" class="search_ ui-autocomplete-input" style="width:100%;" value="" autocomplete="off">
<input type="text" id="grid_6_client_businame" class="search_" style="width:100%;" value="">
<input type="text" id="grid_6_collnurs" class="search_" style="width:100%;" value="">
Now i want to retrieve all those text boxes value which has class 'search_' and those id starts with 'grid_5', How i ca
现在我想要检索所有那些具有“search_”类的文本框值,这些id以'grid_5'开头,How i ca
2 个解决方案
#1
2
You can use combine multiple conditions like
您可以使用组合多个条件
$('input.search_[id^=grid_5]')
#2
0
You need to checkthe IDs using regex .match()
and filter out the qualifying IDs using .filter()
.
您需要使用regex .match()检查ID,并使用.filter()过滤掉符合条件的ID。
Working Code Snippet:
工作代码片段:
var filteredTextboxes = $("input.search_").filter(function(element){
var id = this.getAttribute('id');
if(id.match(/^grid_5/))
return id;
});
console.dir(filteredTextboxes);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="grid_5_collect_businame" class="search_ ui-autocomplete-input" style="width:100%;" value="" autocomplete="off">
<input type="text" id="grid_5_client_businame" class="search_" style="width:100%;" value="">
<input type="text" id="grid_5_collnurs" class="search_" style="width:100%;" value="">
<input type="text" id="grid_6_collect_businame" class="search_ ui-autocomplete-input" style="width:100%;" value="" autocomplete="off">
<input type="text" id="grid_6_client_businame" class="search_" style="width:100%;" value="">
<input type="text" id="grid_6_collnurs" class="search_" style="width:100%;" value="">
Readup:
.match()
| MDN.getAttribute()
| MDN
.match()| MDN
.getAttribute()| MDN
#1
2
You can use combine multiple conditions like
您可以使用组合多个条件
$('input.search_[id^=grid_5]')
#2
0
You need to checkthe IDs using regex .match()
and filter out the qualifying IDs using .filter()
.
您需要使用regex .match()检查ID,并使用.filter()过滤掉符合条件的ID。
Working Code Snippet:
工作代码片段:
var filteredTextboxes = $("input.search_").filter(function(element){
var id = this.getAttribute('id');
if(id.match(/^grid_5/))
return id;
});
console.dir(filteredTextboxes);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="grid_5_collect_businame" class="search_ ui-autocomplete-input" style="width:100%;" value="" autocomplete="off">
<input type="text" id="grid_5_client_businame" class="search_" style="width:100%;" value="">
<input type="text" id="grid_5_collnurs" class="search_" style="width:100%;" value="">
<input type="text" id="grid_6_collect_businame" class="search_ ui-autocomplete-input" style="width:100%;" value="" autocomplete="off">
<input type="text" id="grid_6_client_businame" class="search_" style="width:100%;" value="">
<input type="text" id="grid_6_collnurs" class="search_" style="width:100%;" value="">
Readup:
.match()
| MDN.getAttribute()
| MDN
.match()| MDN
.getAttribute()| MDN