gpt4 book ai didi

Javascript boolean 参数未正确传递

转载 作者:行者123 更新时间:2023-11-30 15:54:46 25 4
gpt4 key购买 nike

我创建了一个包含各种 if 语句的函数,如果参数为真,该函数将被执行。但是将 false 作为参数传递似乎不起作用。我做错了什么?

function easySlider(titleP, subTitleP, overlayP) {
var title = titleP;
var subTitle = subTitleP;
var overlay = overlayP;

if (title === true) {
$(".sliderTitle").css("display", "block");
} else {
$(".sliderTitle").css("display", "none");
}

if (subTitle === true) {
$(".sliderSubTitle").css("display", "block");
} else {
$(".sliderSubTitle").css("display", "none");
}

if (overlay === true) {
$(".sliderOverlay").css("display", "block");
} else {
$(".sliderOverlay").css("display", "none");
}
}

easySlider(true, false, true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<h2 class="sliderTitle">Hello sliderTitle</h2>
<h3 class="sliderSubTitle">Hello sliderSubtTitle</h3>
<div class="sliderOverlay">Hello sliderOverlay</div>

最佳答案

你可以试试这个

<div class="sliderTitle"></div>
<div class="sliderSubTitle"></div>
<div class="sliderOverlay"></div>

<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
function easySlider(title, subTitle , overlay) {
var titleDisplay = title ? 'block' : 'none';
var subTitleDisplay = subTitle ? 'block' : 'none';
var overlayDisplay = overlay ? 'block' : 'none';

$(".sliderTitle").css("display", titleDisplay);
$(".sliderSubTitle").css("display", subTitleDisplay);
$(".sliderOverlay").css("display", overlayDisplay);
}

easySlider(false, false, false);
</script>

关于Javascript boolean 参数未正确传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38748797/

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