Javascript 如何基于下拉选择检查tr是否显示/隐藏
我有三个选项的选择标签:重要,中等重要,不太重要;在每次选择中,我只想显示表中包含这些数据的元素 另一方面,我想添加逻辑,告诉我某些tr是显示还是隐藏(我想将显示的材质添加到数组) 这是我的代码,我应该如何实现这个逻辑Javascript 如何基于下拉选择检查tr是否显示/隐藏,javascript,jquery,Javascript,Jquery,我有三个选项的选择标签:重要,中等重要,不太重要;在每次选择中,我只想显示表中包含这些数据的元素 另一方面,我想添加逻辑,告诉我某些tr是显示还是隐藏(我想将显示的材质添加到数组) 这是我的代码,我应该如何实现这个逻辑 <select id="mySelector" class="styled-select slate" style="width:280px; height:35px"> <option value='important'>აირჩი
<select id="mySelector" class="styled-select slate" style="width:280px; height:35px">
<option value='important'>აირჩიე</option>
<option value='very important'>very important</option>
<option value='middle important'>middle important</option>
<option value='not so important'>not so important</option>
</select>
//selection code
$(document).ready(function($) {
$('#mySelector').change( function(){
var selection = $(this).val();
$('table')[selection? 'show' : 'hide']();
if (selection) {
$.each($('#myTable tbody tr'), function(index, item) {
$(item)[$(item).is(':contains('+ selection +')')? 'show' : 'hide']();
});
}
});
});
$scope.selectAll = function(){
document.querySelector('#myTable1').style.display = 'block';
for (var i = 0; i < $scope.realJsonArray.length; i++) {
var item = $scope.realJsonArray[i];
console.log(item.id+"id======================");
issync1(item);}
};
<tr id="input1">
<td><input type="checkbox" ng-change="sync(selected[item.id],item)" ng-checked="isChecked(item.id)" name="checkData" ng-model="selected[item.id]" ng-false-value="undefined" /></td>
<td>{{item.id}}</td>
<td>{{item.organizationNameEN}}</td>
<td>{{item.organizationNameGE}}</td>
<td>{{item.priority}}</td>
<td><button class="btn btn-default btn-xs" ng-click="toggle($index)"><span class="glyphicon glyphicon-eye-open"></span></button></td>
</tr>
აირჩიე
非常重要
中等重要
不那么重要
//选择代码
$(文档).ready(函数($){
$('#mySelector')。更改(函数(){
var selection=$(this.val();
$('table')[选择?'show':'hide']();
如果(选择){
$.each($('#myTable tbody tr'),函数(索引,项){
$(item)[$(item).is(':contains('+selection+'))?'show':'hide']);
});
}
});
});
$scope.selectAll=function(){
document.querySelector(“#myTable1”).style.display='block';
对于(变量i=0;i<$scope.realJsonArray.length;i++){
var item=$scope.realJsonArray[i];
console.log(item.id+“id=”);
issync1(项目);}
};
{{item.id}
{{item.organizationNameEN}
{{item.organizationNameGE}
{{item.priority}
p、 s my table标记id是myTable1您可以使用
$。toggleClass()
:
$(函数(){
$('input')。关于('change',函数(e){
$('p').toggleClass('hide',this.checked);
});
});代码>
.hide{
显示:无;
}
显示/隐藏
这是第
段,请参考以下代码,这可能会满足您的要求
<table>
<tr><td></td><td>id</td> <td>name</td> <td>address</td> <td>classA</td> <td>classB</td></tr>
<tr ng-repeat="employee in employees">
<td><input type="checkbox" ng-model="employee.checked" ng-true-value="1" ng-false-value="0"></td>
<td>{{employee.id}}</td>
<td>{{employee.name}}</td>
<td>{{employee.address}}</td>
<td><input type="checkbox" ng-model="employee.classA"></td>
<td><input type="checkbox" ng-model="employee.classB"></td>
</tr>
</table>
app.controller('MainCtrl', function($scope) {
$scope.employees = [
{ id:"1", name: "A", address: "A1", classA: true, classB: true },
{ id:"2", name: "B", address: "A2", classA: false, classB: true },
{ id:"3", name: "C", address: "A3", classA: true, classB: false },
{ id:"4", name: "D", address: "A4", classA: false, classB: true },
{ id:"5", name: "E", address: "A5", classA: false, classB: true },
];
$scope.getSelected = function () {
var ar = $scope.employees.filter(
function (value) {
if (value.checked == 1) {
return true;
} else {
return false;
}
}
);
return ar;
};
});
id名称地址classA classB
{{employee.id}
{{employee.name}
{{employee.address}
应用程序控制器('MainCtrl',函数($scope){
$scope.employees=[
{id:“1”,姓名:“A”,地址:“A1”,类别A:true,类别B:true},
{id:“2”,姓名:“B”,地址:“A2”,类别A:假,类别B:真},
{id:“3”,姓名:“C”,地址:“A3”,类别A:真,类别B:假},
{id:“4”,姓名:“D”,地址:“A4”,类别A:假,类别B:真},
{id:“5”,姓名:“E”,地址:“A5”,类别A:假,类别B:真},
];
$scope.getSelected=函数(){
var ar=$scope.employees.filter(
函数(值){
如果(value.checked==1){
返回true;
}否则{
返回false;
}
}
);
返回ar;
};
});
hi@Arvind,谢谢你的回复,顺便问一下,你知道我如何检查raw是否被选中,我的意思是我可以使用任何函数来告诉我行是否被选中(如果被选中,它可以以其他方式返回true和false,例如)