jQuery text()加载方法(jQuery text() Method with loading)

编程入门 行业动态 更新时间:2024-10-26 06:28:22
jQuery text()加载方法(jQuery text() Method with loading)

我尝试创建注销按钮,但我不知道要使用什么。

如何在几秒钟内将注销文本更改为“正在等待......”,然后切换到“成功”?

我仍然需要学习jQuery。

function logout() { $("#logout").text("Waiting...", 3000); $("#logout").text("Success!", 1000); closeWindow(); } document.addEventListener('DOMContentLoaded', function() { document.getElementById('logout').addEventListener('click', logout); });

HTML:

<button type="button" class="list-group-item" id="logout"> Log out</button>

你能帮我提供参考吗?

我从这篇参考文献中了解到: W3Schools.com

I try to create Logout button, but I have no idea what to use.

How to keep the logout text changed to "Waiting.." in a few seconds, after which it switches to "Success"?

I still need to learn jquery.

function logout() { $("#logout").text("Waiting...", 3000); $("#logout").text("Success!", 1000); closeWindow(); } document.addEventListener('DOMContentLoaded', function() { document.getElementById('logout').addEventListener('click', logout); });

HTML :

<button type="button" class="list-group-item" id="logout"> Log out</button>

Can you help me with references?

I learned from this reference : W3Schools.com

最满意答案

document.addEventListener('DOMContentLoaded' ....不需要,3秒后click按钮更新Success消息。使用setTimeout来引入延迟

function logout() {
  $("#logout").text("Waiting...", 3000);
  setTimeout(function() {
    $("#logout").text("Success!", 1000);
  }, 3000)
}
document.getElementById('logout').addEventListener('click', logout); 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" class="list-group-item" id="logout"> Log out</button> 
  
 

document.addEventListener('DOMContentLoaded' .... is not needed & on click of the button update with Success message after 3 secs. Use setTimeout to introduce the delay

function logout() {
  $("#logout").text("Waiting...", 3000);
  setTimeout(function() {
    $("#logout").text("Success!", 1000);
  }, 3000)
}
document.getElementById('logout').addEventListener('click', logout); 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" class="list-group-item" id="logout"> Log out</button> 
  
 

更多推荐

本文发布于:2023-07-04 17:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027058.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   方法   text   jQuery   Method

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!