一、提交表单
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>提交表单</title>
<!--MD5工具类-->
<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
</head>
<body>
<form action="#" method="post">
<p>
<span>用户名:</span><input type="text" id="username" name="uname">
</p>
<p>
<span>密码:</span><input type="password" id="password" name="pwd">
</p>
<!--绑定事件 onclick被点击-->
<button type="submit" onclick="aaa()">提交</button>
</form>
<script>
function aaa(){
var uname = document.getElementById('username');
var pwd = document.getElementById('password');
console.log(uname.value);
console.log(pwd.value);
//MD5算法
pwd.value = md5(pwd.value);
console.log(pwd.value);
}
</script>
</body>
</html>
初识jQuery
jQuery:公式:$(selector).action()
JavaScript
jQuery库,里面存在大量的JavaScript函数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>初识jQuery</title>
<!--jQuery官网:https://jquery.cuishifeng.cn/-->
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
//选择器就是css的选择器
<!--公式:$(selector).action()-->
<a href="" id="test-jquery">点我</a>
<script>
$('#test-jquery').click(function (){
alert('Hello.jQuery')
})
</script>
</body>
</html>
2.1选择器
<script>
//jQuery css中的选择器它全部都能用
$('p').click();//标签选择器
$('#id1').click();//id选择器
$('.class1').click();//class选择器
</script>
文档工具站:https://jquery.cuishifeng.cn/
2.2事件
鼠标事件、键盘事件、其他事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>事件</title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<style>
#divMove{
width: 500px;
height: 500px;
border: 1px solid red;
}
</style>
</head>
<body>
<!--要求:获取鼠标当前的一个坐标-->
mouse: <span id="mouseMove"></span>
<div id="divMove">
在这里移动鼠标
</div>
<script>
//当网页元素加载完毕之后,响应事件
$(function (){
$('#divMove').mousemove(function (e){
$('#mouseMove').text('x:'+e.pageX + 'y:'+e.pageY)
})
});
</script>
</body>
</html>