简体   繁体   English

Javascript入门:如何将预加载器添加到HTML onClick?

[英]Javascript Beginner: How do I add preloader to HTML onClick?

I have a script set up that is running fine, but it takes a while to load and I would like to use a "loading" image before the script loads so that the user is not lost. 我有一个运行良好的脚本设置,但是加载需要一段时间,并且我想在脚本加载之前使用“加载”映像,以免用户丢失。

Currently I am using this in my HTML 目前,我正在HTML中使用它

<div style="text-align:center;">
<a style="color:blue;" onclick="javascript:launchWS('http://clients.mindbodyonline.com/ws.asp?studioid=888888&amp;stype=-9&amp;sView=day&amp;sTrn=2');" href="#">Book Online</a>
</div><br />


I have been trying to add various snippets of javascript I have found around the web into the onclick"" but it breaks the functionality of the root code. 我一直在尝试将在网上找到的各种JavaScript代码片段添加到onclick“”中,但它破坏了根代码的功能。

My guess is that I need to write the whole thing out with javascript, but I'm lost on where to even begin. 我的猜测是我需要用javascript编写整个内容,但我什至不知道从哪里开始。 Everything I find assumes you have a firm grasp of how to implement javascript. 我发现的所有内容都假定您对如何实现javascript有所了解。 Unfortunately, I'm just a beginner, but I would really like to get this working. 不幸的是,我只是一个初学者,但是我真的很想让它工作。

First they way you are writing code is not wrong but it recommended to use script tag and write your javascript code there. 首先,他们编写代码的方式没有错,但建议您使用脚本标记并在其中编写JavaScript代码。 We use 我们用

$(ready).document({}) 

to run the javascript after page load so do not use this one may be helpful for you. 在页面加载后运行javascript,因此不要使用此选项可能对您有所帮助。

What I understand is that you need to show a spinner till the script is loaded- 我了解的是,在脚本加载之前,您需要显示一个微调器-

There are multiple ways to go about this-using a image to block UI until script loads etc. 有多种解决方法-使用图像阻止UI,直到脚本加载等。

But the easiest way is to use a plugin -Spin.js found at http://fgnass.github.io/spin.js/ 但是最简单的方法是使用http://fgnass.github.io/spin.js/上的 -Spin.js插件

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在HTML中加载JavaScript onclick? - How do I load a JavaScript onclick in HTML? 如何在 javascript 中添加 div onclick? - How do I add a div onclick in javascript? 如何在没有使用javascript的id的情况下向html标签添加onclick事件? - How do I add an onclick event to html tags without id's using javascript? 如何为预加载器添加延迟,以便即使在页面加载几秒钟后预加载器也会显示 - How do I add a delay to preloader so the preloader will display even after page load for a couple of seconds 如何在 javascript 中使用 html 中的元素进行 onclick 事件? - How do I use elements from html in javascript for an onclick event? 如何在javascript中为div添加onclick函数? - How do I add an onclick function to a div in javascript? 如何将 function 和 href 添加到 javascript 单个 onclick ZC1C425268E68385D1AB5074F919Z? - How do I add a function and href to javascript single onclick function? 初学者:我将博客集成到我的 Javascript/React 网站中,但如何添加样式? - Beginner: I integrated a blog into my Javascript/React website, but how do I add styling? 预加载器 javascript + css + html - Preloader javascript + css + html HTML / JavaScript的新手,如何使用onclick更改JavaScript的背景颜色 - Very new to HTML/JavaScript, how do I use onclick to change background color with JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM