gpt4 book ai didi

javascript - 将 jQuery 转换添加到函数中

转载 作者:行者123 更新时间:2023-12-03 00:00:29 27 4
gpt4 key购买 nike

我有一个 onclick 函数,可以删除 HTML div 上的 display:none 样式。

function myFunctionUnder18() {
document.getElementById("myAgeMessage").style.display = "block";
}
<input type="radio" name="age" onclick="myFunctionUnder18()" >
<div style="display: none;" id="myAgeMessage"><p>Sorry. You need to be at least 18 years of age.</p></div>

有没有办法在函数中添加jQuery效果,使消息显示流畅?

最佳答案

您可以将持续时间(以毫秒为单位)传递给 .show() .

其中持续时间

A string or number determining how long the animation will run.

function myFunctionUnder18() {
$("#myAgeMessage").show(1000);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="radio" name="age" onclick="myFunctionUnder18()" >
<div style="display: none;" id="myAgeMessage"><p>Sorry. You need to be at least 18 years of age.</p></div>

您还可以使用fadeIn() :

function myFunctionUnder18() {
$("#myAgeMessage").fadeIn(1000);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="radio" name="age" onclick="myFunctionUnder18()" >
<div style="display: none;" id="myAgeMessage"><p>Sorry. You need to be at least 18 years of age.</p></div>

关于javascript - 将 jQuery 转换添加到函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55197906/

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