gpt4 book ai didi

javascript - Jquery精炼表结果: two or more logic statements

转载 作者:行者123 更新时间:2023-11-28 06:23:12 25 4
gpt4 key购买 nike

如果表的值与两个语句都匹配,我想隐藏它们在我的 Fine() 函数中,这两个语句单独工作,但如果它们一起运行,则以第二个运行的为准,

我想要一种表达方式

如果语句a和语句b为真,则同时执行

<html>
<body>

<select id="gender" name="gender">
<option value="">Both</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>

<select id="region" name="region">
<option value="">All Regions</option>
<option value="East Midlands">East Midlands</option>
<option value="Greater London">Greater London</option>
<option value="Northern Ireland">Northern Ireland</option>
<option value="North West">North West</option>
<option value="North Midlands">North Midlands</option>
<option value="Scotland">Scotland</option>
<option value="South East">South East</option>
<option value="South Midland">South Midlands</option>
<option value="South West">South West</option>
<option value="West Midlands">West Midlands</option>
<option value="Yorkshire & North East">Yorkshire & North East</option>
</select>

<button id="button" onClick="refine()">Refine Results</button>
</body>
</html>

<script>

function refine(){

var gender = document.getElementById('gender').value;
var region = document.getElementById('region').value;

$('#t01 tbody tr').each(function() {
$(this).toggle($('td:eq(1):contains(' + gender + ')', this).length > 0);
})

$('#t01 tbody tr').each(function() {
$(this).toggle($('td:not(:contains(' + region + ')', this).length > 0);
})
}
</script>

编辑后:

想象这就是 table

M 大伦敦

F 大伦敦

M西北

F西北

<小时/>

如果用户选择 Male + North West

它只会显示

中西北

最佳答案

如果我理解正确的话。这可能对你有帮助

    function refine(){

var gender = document.getElementById('gender').value;
var region = document.getElementById('region').value;

$('#t01 tbody tr').each(function() {
var firstMatch = $('td:eq(1):contains(' + gender + ')', this).length > 0;
var secondMatch = $('td:not(:contains(' + region + ')', this).length > 0;

if (firstMatch && secondMatch) {
$(this).toggle(firstMatch);
$(this).toggle(secondMatch);
}
})
}

如果没有,请更具体。

关于javascript - Jquery精炼表结果: two or more logic statements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35342988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com