[英]How can I hide all DIVs that start with the same word except for one DIV that has a specific value
Let's say I have the following DIVs: 假设我有以下DIV:
<div id="IDphoto1">photo1</div>
<div id="IDphoto2">photo2</div>
<div id="IDphoto3">photo3</div>
<div id="IDphoto4">photo4</div>
<div id="IDphoto5">photo5</div>
<scipt>
var IDphotoFromURL = getUrlParameter('IDphoto');
function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
}
</script>
How can I hide all the DIVs which id start with the word IDphoto except for the DIV which ID has the value of IDphotoFromURL? 我如何隐藏ID开头为IDphoto的所有DIV,但ID值为IDphotoFromURL的DIV除外? For instance if IDphotoFromURL= IDphoto3 then all DIVs will be hidden except the one with id = IDphoto3 ...
例如,如果IDphotoFromURL = IDphoto3,则所有DIV将被隐藏,除了ID = IDphoto3的那个...
You could use filter()
for this: 您可以为此使用
filter()
:
$('[id^="IDphoto"]').filter(function() {
return this.id != "IDphoto" + IDphotoFromURL;
}).hide();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.