当前位置:网站首页>原生js动态添加元素
原生js动态添加元素
2022-06-25 15:36:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>原生js动态添加元素</title>
<style>
.phone {
width: 200px;
height: 30px;
}
ul {
width: 200px;
border: 1px solid #eee;
text-align: right;
}
ul li{
list-style: none;
height: 50px;
line-height: 50px;
padding-right: 20px;
border-right: 2px solid #999;
}
ul li:hover {
color: #f00;
border-right: 2px solid #f00;
}
/* .circle1 {
width: 492px;
height: 499px;
border-radius: 50%;
background: #f00;
display: flex;
align-items: center;
justify-content: center;
}
.circle2 {
width: 260px;
height: 434px;
border-radius: 50%;
background: #fff;
} */
</style>
</head>
<body>
<div class="container">
<form action="" id="form">
</form>
<ul id="parentUI">
<li>你好</li>
<li>关于我们</li>
<li>帮助中心</li>
</ul>
</div>
<script>
var formId = document.getElementById("form");
// 创建元素input
var inputPhone = document.createElement("input");
// 设置input的属性
inputPhone.setAttribute("class","phone");
inputPhone.type = "text";
inputPhone.value = "请输入手机号码";
formId.appendChild(inputPhone);
// js动态添加li
var ul = document.getElementById("parentUI");
var li = document.createElement("li");
li.setAttribute("class","list");
li.innerHTML = "联系我们";
ul.appendChild(li);
</script>
</body>
</html>发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/152106.html原文链接:https://javaforall.cn
边栏推荐
- Leetcode121 timing of buying and selling stocks
- What is OA
- Kali modify IP address
- 在打新债开户证券安全吗,需要什么准备
- 剑指 Offer 04. 二维数组中的查找
- Detailed description of crontab command format and summary of common writing methods
- CPU over high diagnosis and troubleshooting
- Binocular 3D perception (I): preliminary understanding of binocular
- Sampling method and descriptive statistical function in R language
- Principle and implementation of MySQL master-slave replication (docker Implementation)
猜你喜欢

Golang uses Mongo driver operation - increase (Advanced)

Websocket (WS) cluster solution
![[paper notes] rethinking and improving relative position encoding for vision transformer](/img/6b/8b1c192e0ce715789465fa9ccaabfc.jpg)
[paper notes] rethinking and improving relative position encoding for vision transformer

基于深度Q学习的雅达利打砖块游戏博弈

Agent and classloader

Several relationships of UML
Open the box to experience rust, come on!!!

Popular cross domain

Sword finger offer 07 Rebuild binary tree

appium服务的启动与关闭踩坑记录
随机推荐
Golang regular regexp package uses -05- extend expand(), cut split() according to the rule
Detailed summary of reasons why alertmanager fails to send alarm messages at specified intervals / irregularly
Sword finger offer 06 Print linked list from end to end
MySQL modifier l'instruction de champ
golang reverse a slice
CPU over high diagnosis and troubleshooting
解析数仓lazyagg查询重写优化
Advertising effect cluster analysis (kmeans)
Arthas source code learning-1
Jz-065 path in matrix
The last glory of the late Ming Dynasty - the battle of Korea
VectorDraw Developer Framework 10.1001 Crack
Efficient pytorch: how to eliminate training bottlenecks
客户经理给的开户链接办理股票开户安全吗?我想开个户
Data feature analysis skills - correlation test
Leetcode121 timing of buying and selling stocks
Finally, we can figure out whether the binding event in the tag is bracketed or not
The situation and suggestions of a software engineering associate graduate who failed in the postgraduate entrance examination
TFIDF and BM25
Could not connect to redis at 127.0.0.1:6379 in Windows