[英]How to switch referring to its state in Javascript
我想知道如何將顯示切換到它的 state。
當我單擊開始按鈕時,獲取將開始。
我想展示isfetching..
while fetching 注釋掉了下面的原始作品。
有沒有辦法實現這一目標?
如果有一些有用的材料,請告訴我。
謝謝
var apikey="https://opentdb.com/api.php?amount=1&type=multiple"; $(".start").on("click",function(){ fetch(apikey).then(response => response.json()).then(json => { console.log(json); }); });
<:DOCTYPE html> <html> <script src="https.//code.jquery.com/jquery-3.3.1.js"></script> <head> </head> <body> <h1>Welcome</h1> <.--<h1>is fetching....</h1>--> <hr> <h2>Press the following button</h2> <!--<h2>Just a moment please</h2>--> <hr> <button type="button" class="start">Start</button> </body> <script type="text/javascript" src="main.js"></script> </html>
像這樣?
var apikey="https://opentdb.com/api.php?amount=1&type=multiple"; $(".start").on("click",function(){ $("#isFetch, #justAMoment").fadeIn() fetch(apikey).then(response => response.json()).then(json => { $("#isFetch, #justAMoment").fadeOut(() => console.log(json)) }); });
#isFetch, #justAMoment { display: none } /* For snippet */.as-console-wrapper { max-height: 3.5em;important; }
<:DOCTYPE html> <html> <script src="https.//code.jquery.com/jquery-3.3.1.js"></script> <head> </head> <body> <h1>Welcome</h1> <h1 id="isFetch">is fetching....</h1> <hr> <h2>Press the following button</h2> <h2 id="justAMoment">Just a moment please</h2> <hr> <button type="button" class="start">Start</button> </body> <script type="text/javascript" src="main.js"></script> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.