gpt4 book ai didi

javascript - 如果这些字符串包含 div 中的页面,我需要显示模式

转载 作者:行者123 更新时间:2023-12-01 03:48:32 24 4
gpt4 key购买 nike

例如,我有 3 个字符串来验证是否包含在页面中,如果该字符串不在该页面中,则模式不会加载到页面上,如果字符串包含在页面加载上,则会打开此模式。

$(document).ready(function() {
$('.fl-product-ref').load(function(){
var lightBox = $('.skuReference');
switch(false) {
case (lightBox.find('LNC-L4139800')):
case (lightBox.find('LNC-L6669601')):
case (lightBox.find('LNC-L6669600')):
lightBox.removeClass('hidden').addClass('visible');
break;
default:
lightBox.addClass('hidden');
break;
}
});
}
<span class="fl-product-ref">
<div class="skuReference">LNC-L4139800</div>
</span>

<div class="skuModal hidden">
This is the modal!
</div>

最佳答案

<!DOCTYPE html>
<html>
<head>
<title></title>

<style type="text/css">
.hidden{
visibility :hidden;
}
</style>
</head>
<body>

<span class="fl-product-ref">
<div class="skuReference">LNC-L4139800</div>
<div class="skuReference">LNC-L4139800</div>
<div class="skuReference">LNC-L6669601</div>
<div class="skuReference">LNC-L4139800</div>
</span>

<div class="skuModal hidden">
This is the modal!
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// $('.fl-product-ref').load(function(){
var arr = $('.skuReference').map(function(index , val){ return $(val).text()});
//["LNC-L4139800", "LNC-L4139800", "LNC-L6669601", "LNC-L4139800"]

switch(true) {
case ($.inArray("LNC-L4139800", arr) !== -1):
case ($.inArray("LNC-L6669601", arr) !== -1):
case ($.inArray("LNC-L6669600", arr) !== -1):
$('.skuModal').removeClass('hidden').addClass('visible');
break;
default:
$('.skuModal').addClass('hidden');
break;
}
//});
});
</script>
</body>
</html>

关于javascript - 如果这些字符串包含 div 中的页面,我需要显示模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43402674/

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