JavaWeb前端: JavaScript 简介
JavaScript基本概念
什么是JavaScript
- JS是运行在浏览器里的解释性语言,能实现浏览器端和用户的直接交互(HTML输出/响应事件/改变HTML内容图像样式);除了变量不区分类型以外,语法和Java类似,有几乎相同的流程控制语法,变量操作符,异常处理。
JavaScript有什么作用
JavaScript主要用于实现前端的动态交互:
- JS操作DOM元素:浏览器根据HTML规范把HTML文档渲染成一棵DOM树,HTML标签对应一个个元素,HTML标签内的属性对应为元素的属性,HTML标签关联的文本对应为元素的文本.JS 可以根据HTML标签对应的(标签名,id, class) 查找到标签对应的元素,并且通过元素取出对应的属性值/文本值/样式,并对这些进行更改;达到动态交互的效果
- JS响应用户请求事件:JS可以捕获Web页面上各个元素的事件状态(鼠标事件,键盘事件),并且通过脚本动态的响应用户的请求。前段的交互(字段的校验:邮箱格式/用户名格式/日期格式/是否为空,计时,UI展现的动态效果..)都应该由JS来实现,速度快并且不对后台服务器造成压力。
JS开发注意事项
- JS可以引入到Html中,也可以直接定义在Html中;一个HTML里面可以有多个JS片段,这些JS片段按页面的先后顺序执行。通常把JS Function定义在Head中,把JS脚本定义在Body的最底端,避免先后顺序造成的JS执行异常。
Javascript有执行顺序和引入顺序!!!
Javascript有执行顺序和引入顺序!!!
Javascript有执行顺序和引入顺序!!! 重要的事情说三遍,metisMenu Jquery插件调试了好几天都没有运行成功,后来发现是引入顺序的问题。metisMenu方法的加载调用metisMenu.js,metisMenu.js基于Jquery,因此必须在metisMenu执行之前引入Jquery,从上至下顺序:
.引入jquery.js
.引入MetisMenu.js
.加载metisMenu方法
$('menu').metismenu()
- JS调试相对困难,有些错误在编译时不能被识别(变量,脚本的调用顺序不对或者是语法错误都会导致界面不能正常显示或者是响应),用浏览器打开也不会报错,只是不能正常显示或执行。实际调试通常采用Firebug或者是Chrome工具断点(alert)调试。
- JS开发框架:Sublime比Eclipse更适合用作前端开发,有很多较好的插件来帮助代码补全,标示不同元素的颜色,简化开发速度。Eclipse对前端和Mobile的开发较为有限。常用开发工具:Sublime+PackageControl+EMMET
- JS的具体语法可以查询W3C School,有非常多的实例参考。
JavaScripts & HTML DOM
JS基于HTML DOM对象模型响应用户请求,首先通过HTML DOM定位出元素,在此基础上对DOM对象进行样式改变,捕获DOM对象事件并响应,为DOM对象增加或删除子元素。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjgAAAHECAIAAAC7r8deAAAgAElEQVR4nO3dPZLrxtWAYXDkwIEW4sBVdsDZiQMnTkwFXozo1PV5FQ7u2KG3YY0DBw4dKFCqO/gCzmCa3eccdDf+Tjffp1QqDgYEmrxXeNUkSAw//vjjjz/+OAIA4NJAqAAAnhEqAIBrhAoA4BqhAgC4RqgAAK4RKgCAa4QKAOAaoQIAuEaoAACuESoAgGuECgDgGqECALhGqAAArhEqAIBrhGrGMAy/+c1v0oXDMBwyHgB4NHWher2eh2EYLi8fC14uwzAM5+vrx68Sl5f3lcL7TSvflrz/eL6+zu76fsuRaUfpCrNjSJ4gQgUAh1o9VKO+6LMf73f8jE5xqD52/b7NeCSfC6JhzI4hdgtV2L2RUAHAjo4J1e2e8c81oYoWJL+NBzI7huCpuZcuoVUAsIMDQnU+n4fhfH19ubzfXhaqcA4lbuBu4ewYkidoGP72t79N/2ZGBQA7WxSqWF6oLtfreUrFNXylri5UwRJpQnU/ktkx3D87w0CoAOBYB8yoLi8fnXuf0qweqvkZlT6G+2fnw61Sf/jDH6JiAQC2dkio3m9ON/Z/j0ofQ/DUBH26/TjdIFQAsJuDQiUvW+Osv+j38SZnxxATJ1KECgB24zFUd+J8rPM5qqJQpX0iVACwG76ZYobYJEIFALshVDPSJoVzLADA1ggVAMA1QgUAcI1QAQBcI1QAANcIFQDANUIFAHCNUAEAXCNUAADXCBUAwDVCBQBwjVABAFwjVAAA1wgVAMA1QgUAcI1QAQBcI1QAANcIFQDANUIFAHCNUAEAXCNUAADXCBUAwDVCBQBwjVABAFwjVAAA1wgVAMA1QgUAcI1QAQBcI1QAANcIFQDANUIFAHCNUAEAXCNU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sr5NG70JRE5V5HPGVL08d667QCIOA8Vl6LPDYzxIV9xYWnM8rdvPArxx/wd2bRrw9eFSvs+2ei2OAADrQIqcCn6li5Fb+SkqC4Vq2nbT8cjLrE3NRuh9L5aY9LlRoSWhyrneonG4yJaQA4uRR/tKFjb8aXoRzNdOUd8cSTpr+ztFD2KzD1qvzKGpIVKWzP67vPoe9DTdC0MFTUCFuJS9JOWLkWfLi+9ixEho0PR7XSD4u6iLYv7MoYkPhbtBb0huUqh+EV8UbHEOGnjKV2HS1IBC3Ep+sYuRS/etn9lr5NzY/a+RRvU7i4OO6dkWhhml0Q3Mq/WES3Pf9lQ3DWAWVyKvqVL0acr5EdFux0NrGibUS3Ex5LeMJaLRkn+y3Hakuilv01DlfOuGAANl6Jv6VL06QrGkszb9g07HvbGtRaKd09/zB/M1JvRvPZuuo7471GfBkU/aq8ZGisTKqCC89PTx3HkUvRWh2ZXmL1t5CfnvtqoxNVmQyUaJavMqNYK1Zgxu+LNKqCa51BxKXrhx3Rl8S7avrTxiDcyt6+tYATJXm7sQrPwpb8xb1YU/Zj/yWJ7+wBsnkPl1XGXok+3Y6xmLzEO+kWhMu4lDjWzx/bCce59o5wl9jtJ9vOTvvQ3BKe52/WiUkApQlXO2aXoo41opUnvNbtO0ULjUWgbmQ2V9ljSHoS/yj/rL/0x/6NR4bQs3f5wf46GHTwANkIFAHCNUAEAXCNUAADXCBUAwDVCBQBwjVABAFwjVAAA1wgVAMA1QgUAcI1QAQBcI1QAANcIFQDANUIFAHCNUAEAXCNUAADXCBUAwDVCBQBwjVABAFz7f+lY0GRzx2jpAAAAAElFTkSuQmCC" alt="" />
JS查找元素(可以逐层定位,先找到父元素,再用父元素查找子元素)
- 通过 id 找到 HTML 元素:var x=document.getElementById("main")
- 通过标签名找到 HTML 元素:var y=x.getElementsByTagName("p")
- 通过类名找到 HTML 元素:var y=x.getElementsByClass("uname")
JS操作元素(修改文本内容/修改属性/修改样式/新生成元素/删除元素)
- 修改元素文本(innerHTML):document.getElementById(id).innerHTML=new HTML
- 修改元素属性(修改图片显示):document.getElementById("image").src="landscape.jpg";
- 修改元素样式(比如错误高亮,元素显示):document.getElementById("p2").style.color="blue"; document.getElementById('p1').style.visibility='hidden'
- 相应UI事件:
- 鼠标事件:鼠标点击元素(onclick),鼠标移入元素区域(onmouseover),鼠标移出元素区域(onmouseout)
- 加载事件:网页加载时,图片加载时触发(onload, onunload)
- 变更事件(文本框有输入变更):onchange();
- 表单事件:表单提交时触发
- 除了捕获事件,还能生成/移除网页元素:
- var para=document.createElement("p");
- var node=document.createTextNode("这是新段落。");
- para.appendChild(node);
JS响应事件
JS能捕获页面上元素的如下事件:
- 鼠标事件:鼠标点击元素(onclick),鼠标移入元素区域(onmouseover),鼠标移出元素区域(onmouseout)
- 加载事件:网页加载时,图片加载时触发(onload, onunload)
- 变更事件(文本框有输入变更):onchange();
- 表单事件:表单提交时触发
- 除了捕获事件,还能生成/移除网页元素:
- var para=document.createElement("p");
- var node=document.createTextNode("这是新段落。");
- para.appendChild(node);
JavaScript实例
JS基本语法
JS&DOM对象
登陆校验
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Author" content="刘江波">
<script type="text/javascript">
function login(){
var userName=document.getElementById("userName").value;
var pwd=document.getElementById("pwd").value;
var repwd=document.getElementById("repwd").value;
var address=document.getElementById("address").value;
var matchResult=true;
if(userName==""||pwd==""||repwd==""||address==""){
alert("请确认是否有空缺项!");
matchResult=false;
}else if(userName.length<6||userName.length>20){
alert("用户名长度应在6到20个字符之间!");
matchResult=false;
}else if(userName==pwd||userName==repwd){
alert("密码或重复密码不能和用户名相同!");
matchResult=false;
}else if(pwd.length<6||pwd.length>20||repwd.length<6||repwd.length>20){
alert("密码或重复密码长度应在6到20个字符之间!");
matchResult=false;
}else if(pwd!=repwd){
alert("密码和重复密码不同,请重新输入!");
matchResult=false;
}else if(userName.length<6||userName.length>20){
alert("用户名长度应在6到20个字符之间!");
matchResult=false;
} if(matchResult==true){
var mailreg = /^\w+@\w+(\.\w+)+$/;
if(!address.match(mailreg)){
alert("邮箱格式不正确");
matchResult=false;
}
} if(matchResult==true){
if(userName.charAt(0)>=0&&userName.charAt(0)<=9){
alert("用户名不能以数字字符开始!");
matchResult=false;
}
} return matchResult;
}
</script>
<title>用户注册及验证</title>
</head> <body>
<center>
<form name="loginForm" action="http://www.ytu.edu.cn" onsubmit="return login()" method="post">
<table bgcolor="#6666FF" width="300" cellspacing="0" cellpadding="0" border="0" align="left" valign="top">
<tr>
<td class="table-title" colspan="2" align="center" bgcolor="#3366FF">用户注册</td>
</tr>
<tr>
<td width="130" height="28" align="left">登录用户名</td>
<td><input id="userName" name="userName" type="text" class="input"></td>
</tr>
<tr>
<td width="80" height="28" align="left">登录密码</td>
<td><input id="pwd" name="pwd" type="password" class="input"></td>
</tr>
<tr>
<td width="80" height="28" align="left">重复输入密码</td>
<td><input id="repwd" name="repwd" type="password" class="input"></td>
</tr>
<tr>
<td width="80" height="28" align="left">有效邮箱地址</td>
<td><input id="address" name="address" type="text" class="input"></td>
</tr>
<tr> <!--<td width="10" height="28" align="left"></td>-->
<td colspan="2">
<input type="submit" value="登录">
<input type="button" value="取消" onClick="reset()"></td>
</tr>
</table>
</form>
</center> </body>
</html>
Javascript有执行顺序和引入顺序!!!
Javascript有执行顺序和引入顺序!!!
Javascript有执行顺序和引入顺序!!!
重要的事情说三遍,metisMenu调试了好几天都没有运行成功,后来发现竟然是引入顺序的问题,metisMenu方法的加载调用metisMenu.js,metisMenu.js基于Jquery,因此引入的jquery.js必须在metisMenu执行之前,从上至下顺序:
1.引入jquery.js
2.引入MetisMenu.js
3.加载metisMenu方法
$('menu').metismenu()
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
JavaWeb前端: JavaScript 简介的更多相关文章
- 前端JavaScript(1) --Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏
一.Javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) Jav ...
- 《JavaScript高级程序设计(第3版)》阅读总结记录第一章之JavaScript简介
前言: 为什么会想到把<JavaScript 高级程序设计(第 3 版)>总结记录呢,之前写过一篇博客,研究的轮播效果,后来又去看了<JavaScript 高级程序设计(第3版)&g ...
- FeWeb基础之JavaScript简介
FeWeb基础之JavaScript简介 1.JavaScript的基本介绍 JavaScript是一种基于对象和事件驱动并具有安全性能的脚本语言,它是通过嵌入或调入在标准的HTML语言中实现的.Ja ...
- python学习之路前端-JavaScript
JavaScript简介 JavaScript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型.它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本 ...
- Web前端-JavaScript基础教程上
Web前端-JavaScript基础教程 将放入菜单栏中,便于阅读! JavaScript是web前端开发的编程语言,大多数网站都使用到了JavaScript,所以我们要进行学习,JavaScript ...
- python 全栈开发,Day50(Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏)
一.Javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) Jav ...
- 为什么我要放弃javaScript数据结构与算法(第一章)—— JavaScript简介
数据结构与算法一直是我算比较薄弱的地方,希望通过阅读<javaScript数据结构与算法>可以有所改变,我相信接下来的记录不单单对于我自己有帮助,也可以帮助到一些这方面的小白,接下来让我们 ...
- Web前端-JavaScript基础教程下
Web前端-JavaScript基础教程下 <script>有6个属性: async对外部脚本有效,可以用来异步操作,下载东西,不妨碍其他操作. charset为src属性指定字符集. d ...
- 前端JavaScript规范
前端JavaScript规范 http://www.imooc.com/article/1402 http://greengerong.com/blog/2015/05/09/qian-duan-ja ...
随机推荐
- NSArray倒序
NSArray倒序 NSArray *tmparr = [[upLoadImageArr reverseObjectEnumerator] allObjects]; ios 正则表达式替换 . 不可变 ...
- 正则表达式获取字符串中的img标签中的url链接
废话不多说直接看代码 JavaScript中的代码: var re = /src=\"([^\"]*?)\"/i; var arr = str.match(re); if ...
- 解决编译错误: 非法字符: '\ufeff' 解决方案|错误: 需要class, interface或enum
http://www.cnblogs.com/oymx/p/5353235.html 可以 note++打开 在格式里 选择utf-8 无bom格式编码 即可
- overflow:hidden---清除浮动,隐藏溢出
overflow:hidden这个CSS样式是大家常用到的CSS样式,但是大多数人对这个样式的理解仅仅局限于隐藏溢出,而对于清除浮动这个含义不是很了解.一提到清除浮动,我们就会想到另外一个CSS样式: ...
- 【数论】Miller_Rabin
Miller_Rabin素数测试 Miller_Rabin判断单个素数的方法运用了费马小定理,可以说非常之快了. Miller_Rabin曾经被称作“黑科技”,但是根据费马小定理其实完 ...
- Openstack的项目管理方案
openstack作为云的解决方案,必须对某个用户,项目具有资源限制,不能无限制使用资源. 配置 在/etc/nova/nova.conf中,有 quota_driver=nova.quota.DbQ ...
- JQuery基础二
1.表单过滤器 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- Arcgis Server 默认服务端口号修改方法
本人安装Arcgis Server 10.2之后发布了一个地图服务,该服务默认使用的端口号是6080,本人使用的是教育网,使用教育网均能正常使用该服务,但是使用电信或者移动网络均不能正常访问该网站. ...
- pageX/Y, offset(), position(), scrollTop(), screenX/Y, clientX/Y, pageX/Y
event.pageX get mouse position Description: The mouse position relative to the left edge of the docu ...
- JAVA TcpServer端使用Scanner读取不到数据的解决办法
在使用JAVA进行Socket通信时,在Server端使用Scanner的nextLine()方法读取数据时,一直读取不到数据是因为Scanner是一个扫描器,它扫描数据都是去内存中一块缓冲区中进行扫 ...