1.フォーム検証
DOMツリーの形を形成する何
- テキストボックスのテキスト
- ドロップダウンボックス<選択>
- ラジオボタンラジオ
- チェックボックスのチェックボックス
- 隠しフィールド隠し
- [パスワード]ボックスにパスワード
- ......。
フォームの目的:情報を送信します
提出する情報へのアクセス
<form action="post">
<p>
<span>用户名:</span> <input type="text" id="username">
</p>
<!--多选框的值,就是定义好的value -->
<p>
<span>性别:</span>
<input type="radio" name="sex" value="man" id="boy"> 男
<input type="radio" name="sex" value="women" id="girl"> 女
</p>
</form>
<script>
var input_text = document.getElementById('username');
var boy_radio = document.getElementById('boy');
var girl_radio = document.getElementById('girl');
// 得到输入框的值
input_text.value
// 修改输入框的值
input_text.value = '123'
// 对于单选框,多选框等等固定的值,boy_radio.value只能取到当前的值
boy_radio.checked; //查看返回的结果,是否为true,如果为true,则被选中~
girl_radio.checked = true; //赋值
</script>
フォームを送信します。MD5暗号化パスワード、フォームの最適化
<!--
表单绑定提交事件
οnsubmit= 绑定一个提交检测的函数, true, false
将这个结果返回给表单,使用 onsubmit 接收!
οnsubmit="return aaa()"
-->
<form action="https://www.baidu.com/" method="post" onsubmit="return aaa()">
<p>
<span>用户名:</span> <input type="text" id="username" name="username">
</p>
<p>
<span>密码:</span> <input type="password" id="input-password">
</p>
<input type="hidden" id="md5-password" name="password">
<!--绑定事件 onclick 被点击-->
<button type="submit">提交</button>
</form>
<script>
function aaa() {
alert(1);
var uname = document.getElementById('username');
var pwd = document.getElementById('input-password');
var md5pwd = document.getElementById('md5-password');
md5pwd.value = md5(pwd.value);
// 可以校验判断表单内容,true就是通过提交,false,阻止提交
return true;
}
</script>
2.jQery
JavaScriptを
jQueryライブラリ、JavaScript関数の内部がたくさんあります
取得jQueryの
公式 :$(选择器).事件(事件函数)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!--<script src="https://cdn.bootcss.com/jquery/3.4.1/core.js"></script>-->
<script src="lib/jquery-3.4.1.js"></script>
</head>
<body>
<a href="" id="test-jquery">点我</a>
<script>
//选择器就是css的选贼器
$('#test-jquery').click(function () {
alert('hello,jQuery');
})
</script>
</body>
</html>
セレクタ
//原生js,选择器少,麻烦不好记
//标签
document.getElementsByTagName();
//id
document.getElementById();
//类
document.getElementsByClassName();
//jQuery css 中的选择器它全部都能用!
$('p').click(); //标签选择器
$('#id1').click(); //id选择器
$('.class1').click() //class选择器
ドキュメンテーションツールの駅:のhttp://jquery.cuishifeng.cn/
イベント
マウスイベント、キーボードイベント、その他のイベント
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="lib/jquery-3.4.1.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>
営業DOM
ノードのテキスト操作
$('#test-ul li[name=python]').text(); //获得值
$('#test-ul li[name=python]').text('设置值'); //设置值
$('#test-ul').html(); //获得值
$('#test-ul').html('<strong>123</strong>'); //设置值
CSSの操作
$('#test-ul li[name=python]').css({"color","red"})
隠すと表示要素:自然display : none
;
$('#test-ul li[name=python]').show()
$('#test-ul li[name=python]').hide()
エンターテインメントテスト
$(window).width()
$(window).height()
$('#test-ul li[name=python]').toggle();
今後のアヤックス();
$('#from').ajax()
$.ajax({ url: "test.html", context: document.body, success: function(){
$(this).addClass("done");
}});
ヒント
1、JSの統合場合(試合を見るために、ソースコードをjQueryのソースコードを参照してください!)
2、HTMLの統合。CSS(Paのサイト、すべてのダウンダウン、結果を参照するには、対応する修正〜)
レイヤーポップコンポーネント
要素-UI