[英]How can I hide all DIVs that start with the same word except for one DIV that has a specific value
假設我有以下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>
我如何隱藏ID開頭為IDphoto的所有DIV,但ID值為IDphotoFromURL的DIV除外? 例如,如果IDphotoFromURL = IDphoto3,則所有DIV將被隱藏,除了ID = IDphoto3的那個...
您可以為此使用filter()
:
$('[id^="IDphoto"]').filter(function() {
return this.id != "IDphoto" + IDphotoFromURL;
}).hide();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.