【发布时间】:2019-11-04 06:19:50
【问题描述】:
我试图在引导程序中隐藏和显示一些卡片,但我无法弄清楚。 所有卡片都有类卡片(当然),我试图在单击按钮时隐藏所有这些卡片。这是我现在拥有的:
function myFunction() {
jQuery(document).ready(function($) {
$(".card").hide();
});
var game = document.getElementById("game").value;
var resolution = document.getElementById("resolution").value;
var graphic = document.getElementById("graphic").value;
if (game == "Black" && graphic == "high" && resolution == "1080") {
alert("Hello " + game + "! You will now be redirected to www.w3Schools.com");
} else if (book == "Red") {
} else if (book == "Green") {
} else {
}
}
对函数的调用是正确的,因为警报确实可以正常工作。
由于某种原因
jQuery(document).ready(function($) {
$(".card").hide();
});
在 js 函数之外(当它没有连接到按钮时)部分确实有效。
不知道它是否有帮助,但这里也是我的引导文档的片段:
<button type="submit" class="btn btn-primary" id="btn" onclick="myFunction()">Submit</button>
</form>
</div>
<!-- Results -->
<div class="card" id="p2" style="width:200px; margin:30px">
<img class="card-img-top" src="https://image" alt="Card image" style="width:100%">
<div class="card-body">
<h5 class="card-title">Processor</h5>
<p><a href="#">Newegg</a></p>
<p><a href="#">Newegg</a></p>
<p><a href="#">Newegg</a></p>
</div>
</div>
<div class="card" id="p3" style="width:200px; margin:30px">
<img class="card-img-top" src="https://image" alt="Card image" style="width:100%">
<div class="card-body">
<h5 class="card-title">Graphic card</h5>
<p><a href="#">Newegg</a></p>
<p><a href="#">Newegg</a></p>
<p><a href="#">Newegg</a></p>
</div>
</div>
这里是我已经尝试过的东西:
切换How to hide and show bootstrap 4 cards by hovering over navigation menu through css?
标准js document.getElementById(".card").style.display = "none";
我看过 react 的东西,但我不明白。
【问题讨论】:
-
您的问题不在于您的功能,这是您想要的行为的工作小提琴。由于您没有复制所有代码,因此我不得不评论您函数的第二部分:jsfiddle.net/m156gpvr
标签: javascript bootstrap-4 show-hide