我如何将 jquery 代码放在 html 文档中?(灯箱)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1394753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:20:52  来源:igfitidea点击:

how do i put jquery code inside a html document? (lightbox)

jquery

提问by Kevin Li

how do i make the jquery show up in an existing html document. mainly the jquery lightbox plugin

我如何使 jquery 显示在现有的 html 文档中。主要是jquery灯箱插件

edit: ? how do i reference?

编辑: ?我如何参考?

回答by Russ Cam

reference the jQuery script followed by the lightbox script in your html document.Like so,

引用 jQuery 脚本,然后是 html 文档中的灯箱脚本。像这样,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="source-of-jquery.js"></script>
<script type="text/javascript" src="source-of-lightbox-plugin.js"></script>
<script type="text/javascript" src="source-of-script-with-your-jquery-code-in.js"></script>
</head>
<body>

....

then you will need to use the lightbox accordingly. For example, in source-of-script-with-your-jquery-code-in.js

那么您将需要相应地使用灯箱。例如,在source-of-script-with-your-jquery-code-in.js

$(function() {
 $('#gallery a').lightBox({fixedNavigation:true});
});

binds the lightbox plugin to each <a>element that is a child of the element with the id gallery

将灯箱插件绑定到<a>作为具有 id 的元素的子元素的每个元素gallery

EDIT:

编辑:

jQuery is nothing but a JavaScript framework (albeit a great framework). If you're starting out on your front-end web development journey, I would suggest looking at JavaScript in conjunction with jQuery as it is the building block of the framework and will help you to understand how it works better. Here are some resources to get you started

jQuery 只不过是一个 JavaScript 框架(尽管是一个很棒的框架)。如果您开始了前端 Web 开发之旅,我建议您将 JavaScript 与 jQuery 结合使用,因为它是框架的构建块,将帮助您了解它如何更好地工作。这里有一些资源可以帮助您入门

回答by RR.

You need to reference the jquery javascript file you have downloaded in your html

您需要引用您在 html 中下载的 jquery javascript 文件

<script type="text/javascript" src="/path_to_js_files/jquery.js"></script>

You will also need to add a reference to the js file you downloaded for the lightbox plugin.

您还需要添加对为灯箱插件下载的 js 文件的引用。

There is a beginners tutorial on jQuery here.

有jQuery的初学者教程在这里