Today we will look into jQuery Hello World program. In the earlier post, we discussed what is jQuery?. Here we will learn how to download and install it and then run a simple “jQuery Hello World” program.

今天,我们将研究jQuery Hello World程序。 在之前的文章中,我们讨论了jQuery是什么? 。 在这里,我们将学习如何下载和安装它,然后运行一个简单的“ jQuery Hello World”程序。

下载jQuery (Download jQuery)

jQuery is a javascript library and comes in a single JS file, you can download it from jQuery Official Website. There are development and production versions, you can download any one of these to learn jQuery but in a production environment, you should use jQuery minified production version.

jQuery是一个javascript库,位于一个JS文件中,您可以从jQuery Official Website下载。 有开发和生产版本,您可以下载其中的任何一个以学习jQuery,但是在生产环境中,您应该使用jQuery精简生产版本。

安装jQuery (Installing jQuery)

Once you have jQuery JS downloaded, you can use it in any HTML, JSP, PHP files by including it in the head section.

一旦下载了jQuery JS,您就可以在其头部将其包含在任何HTML,JSP,PHP文件中。

<script type="text/javascript" src="jquery-3.2.1.min.js"></script>

Note that the src path is relative here, in above case HTML and jQuery JS file should be in the same directory.

请注意,src路径是相对的,在上述情况下,HTML和jQuery JS文件应位于同一目录中。

jQuery Hello世界 (jQuery Hello World)

Here is our first HTML with jQuery hello world functionality.

这是我们第一个具有jQuery hello world功能HTML。

<html>
<head>
<title>My First jQuery Example</title><script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<script type="text/javascript">$(document).ready(function(){$("#msg").html("<h2>jQuery Hello World</h2>");
});$(document).ready(function() {$("#newdiv").click(function() {alert("Hello world!");});
});</script>
</head><body><p>This is Hello World by HTML</p><div id="msg">
</div><br/><div id="newdiv">
Click on this to see a dialogue box.
</div></body>
</html>

When I open above HTML in a browser, here is what I get after clicking on the last line.

当我在浏览器中打开HTML上方时,这是单击最后一行后得到的内容。

jQuery函数说明 (jQuery Functions Explanation)

$(document).ready(function(){$("#msg").html("<strong>Hello World by JQuery</strong>");
});

$() is the syntax for jQuery function, here when DOM elements are ready or fully loaded, an element with id “msg” HTML is set by this function. Here we are using jQuery for manipulating the HTML data.

$()是jQuery函数的语法,在此情况下,当DOM元素准备就绪或完全加载时,此函数将设置ID为“ msg” HTML的元素。 在这里,我们使用jQuery来处理HTML数据。

$(document).ready(function() {$("#newdiv").click(function() {alert("Hello world!");});
});

Here we are using the mouse click event to show the alert for all the elements with id “newdiv”. That’s all for getting started with jQuery and jQuery hello world program.

在这里,我们使用鼠标单击事件来显示ID为“ newdiv”的所有元素的警报。 这就是开始使用jQuery和jQuery hello world程序的全部。

翻译自: https://www.journaldev.com/887/jquery-hello-world

jQuery Hello世界相关推荐

  1. ajax中的让渡,jQuery必须掌握的API

    这次给大家带来jQuery必须掌握的API,使用jQuery必须掌握的API的注意事项有哪些,下面就是实战案例,一起来看一下. 其中包括jQuery 核心函数和方法.jQuery属性参考手册.jQue ...

  2. jQuery框架学习第二天:jQuery中万能的选择器

    jQuery框架学习第一天:开始认识jQuery jQuery框架学习第二天:jQuery中万能的选择器 jQuery框架学习第三天:如何管理jQuery包装集 jQuery框架学习第四天:使用jQu ...

  3. 从零开始学习jQuery (二) 万能的选择器

    本系列文章导航 从零开始学习jQuery (一) 开天辟地入门篇 从零开始学习jQuery (二) 万能的选择器 从零开始学习jQuery (三) 管理jQuery包装集 从零开始学习jQuery ( ...

  4. 作为曾经的 Web 开发“王者”,jQuery 的传奇怎么续写?

    作为世界上使用最广泛的JavaScript库,jQuery曾经帮助过一代开发人员创建了适用于每种浏览器的网站,可以说,Web开发之所以能有今天,jQuery可谓功不可没.但是随着新的库.框架和范例的不 ...

  5. JQuery:视频+实战总结

    [前言] 整理总结完CSS后,便一鼓作气进入JQuery的世界:由于有了js的基础,所以直接晋级JQuery实战.早就听闻大名鼎鼎的JQuery,这次领教后果然名不虚传. [菜鸟初始JQuery] · ...

  6. jquery获取img的src值_JQuery

    JQuery 主要内容 Jquery对象 ​ jQuery 是一套兼容多浏览器的 javascript 脚本库. 核心理念是写得更少,做得更多,使用 jQuery 将极大的提高编写 javascrip ...

  7. [乐意黎转载]从零开始学习jQuery (二) 万能的选择器

    一.摘要 本章讲解jQuery最重要的选择器部分的知识. 有了jQuery的选择器我们几乎可以获取页面上任意的一个或一组对象, 可以明显减轻开发人员的工作量. 二.前言 编写任何javascript程 ...

  8. jQuery 从零开始学习 (二) 选择器

    一.摘要 本章讲解jQuery最重要的选择器部分的知识. 有了jQuery的选择器我们几乎可以获取页面上任意的一个或一组对象, 可以明显减轻开发人员的工作量. 二.前言 编写任何javascript程 ...

  9. jQuery (JavaScript 脚本库)

    jQuery 简介: 是一套兼容多浏览器的 javascript 脚本库. jQuery 在 2006 年 1 月由美国人 John Resig 在纽约的 barcamp 发布,由 Dave Meth ...

最新文章

  1. 用EC5/EC6自定义class的区别及用法 -- Phaser3网页游戏框架
  2. Build Docker image of a Python Flask app【转载】
  3. Python 模块初始化的时候,发生了什么?
  4. SQL Server 中系统视图sysobjects中type字段的说明
  5. BZOJ 1396:识别子串 SA+树状数组+单调队列
  6. 用Python标准库turtle画一只老虎,祝您新年虎虎生威,大吉大利
  7. Modeling Deformable Objects from a Single Depth Camera
  8. CentOS 7操作系统中设置系统时间/时区的方法
  9. 完全卸载mysql步骤
  10. MicroDicom viewer(Dicom格式看图软件)v2.9.2官方版
  11. python程序员工资待遇-为什么企业很难招聘到好的python程序员?
  12. iOS-instrument使用
  13. 数码计算机英语单词,数码相机的规格词汇中英对照
  14. kubectl源码分析之rollout undo
  15. Golang创建DLL
  16. ISO-5055: Automated Source Code Security Measure Element Descriptions
  17. PKCS #5: Password-Based Cryptography Specification Version 2.1 中文翻译
  18. office365在线安装太慢,换离线安装终于搞定
  19. 黑苹果安装界面选择语言
  20. 晶体三极管工作模式判断

热门文章

  1. pmm 监控mysql、mongodb、系统
  2. 【Python】Scrapy入门实例
  3. BZOJ1075 : [SCOI2007]最优驾车drive
  4. Java对MySql数据库进行备份与还原
  5. Java实践(五)——类的声明与引用
  6. [转载] python3 opencv 图像二值化笔记(cv2.adaptiveThreshold)
  7. [转载] opencv-python:13_图像噪声(噪声的概念、椒盐噪声、高斯噪声、使用python给图像添加噪声)
  8. [转载] python随笔2(列表的增删改查)
  9. vue nextTick深入理解-vue性能优化、DOM更新时机、事件循环机制
  10. jdbcdbcpc3p0