[英]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&stype=-9&sView=day&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.