当前位置:网站首页>DOM and its applications
DOM and its applications
2022-08-05 05:23:00 【A long way to go】
DOM及其应用
1.编写一个登录页面,Verify that the username and password conform to the specification on the client side.
账户为:123
密码为:456
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="https://www.baidu.com/" onsubmit="return fn()">
<input type="text" name="userName" />
<input type="password" name="passWord" />
<button type="submit" >点我</button>
</form>
<script>
function fn() {
var flag=true;
var myUserName = document.querySelectorAll("input")[0];
var myPassWord = document.querySelectorAll("input")[1];
if (myUserName.value == "123") {
if (myPassWord.value == "456") {
alert("验证成功");
return flag;
}
else {
flag = false;
alert("密码错误,请重新输入");
return flag;
}
}
else {
flag = false;
alert("用户名错误,请重新输入!");
return flag;
}
}
</script>
</body>
</html>
运行截图:
2.Write a table component.Two-dimensional table data is required to be separated from the table display,不使用任何框架.This question can be used as a course assessment development project.
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<script type="text/javascript">
window.onload = function(){
//增加行
var btn = document.getElementById("a");
btn.onclick = function(){
var table = document.getElementsByTagName("table")[0];
add(table,"tr");
}
//删除行
var a = document.getElementsByTagName("a");
for(var i=0;i<a.length;i++){
a[i].onclick =function(){
var parentTwo = this.parentNode.parentNode;
var parentThree = parentTwo.parentNode;
remove(parentTwo,parentThree);
}
}
//Mouse movement changes the color
var tr = document.getElementsByTagName("tr");
for(var i=0;i<tr.length;i++){
tr[i].onmouseover = function(){
background(this,"red");
};
tr[i].onmouseout = function(){
background(this,"white");
}
}
};
//改变颜色的函数
function background(obj,target){
obj.style.background = target;
}
//删除的函数
function remove(two,three) {
three.removeChild(two);
}
//Add functions for delete operations in rows
function remover(obj) {
var remove1=document.getElementById('table').childNodes[1];
var remove2=obj.parentNode.parentNode;
remove1.removeChild(remove2);
}
//function to add row
function add(parent,child) {
var newone=document.createElement("tr");//新增行
newone.onmouseover = function(){
background(this,"red");
};
newone.onmouseout = function(){
background(this,"white");
};
var newone1=document.createElement("td");
newone1.innerHTML="<td />";
newone.appendChild(newone1);
var newone2=document.createElement("td");
newone2.innerHTML="<td />";
newone.appendChild(newone2);
var newone3=document.createElement("td");
newone3.innerHTML="<a href='javascript:;' οnclick='remover(this)' >删除</a>";
newone.appendChild(newone3);
document.getElementById("table").childNodes[1].appendChild(newone);
}
</script>
</head>
<body>
<table border="1" width="50%" id="table">
<tr>
<th>学号</th>
<th>姓名</th>
<th>操作</th>
</tr>
<tr>
<td>001</td>
<td>张三</td>
<td><a href="javascript:;" >删除</a></td> <!--在删除按钮上添加点击事件 -->
</tr>
<tr>
<td>002</td>
<td>李四</td>
<td><a href="javascript:;" >删除</a></td> <!--在删除按钮上添加点击事件 -->
</tr>
</table>
<input id ="a" type="button" value="添加一行" /> <!--在添加按钮上添加点击事件 -->
</body>
</html>
运行截图:
边栏推荐
- How does the Flutter TapGestureRecognizer work
- uva1325
- [Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)
- 物理层的接口有哪几个方面的特性?各包含些什么内容?
- [WeChat applet] WXML template syntax - conditional rendering
- 【记一下1】2022年6月29日 哥和弟 双重痛苦
- The difference between span tag and p
- Flutter real machine running and simulator running
- redis复制机制
- C#关于set()和get()方法的理解及使用
猜你喜欢
【Transfer】What is etcd
【过一下7】全连接神经网络视频第一节的笔记
How can Flutter parent and child components receive click events
Flutter学习三-Flutter基本结构和原理
【过一下6】机器视觉视频 【过一下2被挤掉了】
2022 Hangzhou Electric Multi-School 1st Session 01
Excel Paint
Pycharm中使用pip安装第三方库安装失败:“Non-zero exit code (2)“的解决方法
u-boot debugging and positioning means
第四讲 反向传播随笔
随机推荐
判断语句_switch与case
Difference between for..in and for..of
[Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)
RDD和DataFrame和Dataset
Mesos学习
【过一下12】整整一星期没记录
[cesium] element highlighting
u-boot中的u-boot,dm-pre-reloc
human weakness
2022杭电多校第一场01
Dephi reverse tool Dede exports function name MAP and imports it into IDA
Requests the library deployment and common function
uva1325
第5讲 使用pytorch实现线性回归
coppercam入门手册[6]
【过一下7】全连接神经网络视频第一节的笔记
【过一下 17】pytorch 改写 keras
Multi-threaded query results, add List collection
1.3 mysql批量插入数据
Database experiment five backup and recovery