8 JS - dom操作

1 dom中查找html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>lizi</title>
<style>
.ptest
{
    font-size:40px;
} 
</style>
</head>
<body>
    
<p id="lizi"></p>
<p ></p>
<p class="ptest"></p>
    
姓:<input type="text" name="username">
名:<input type="text" name="username">


<script>
var element=document.getElementById("lizi");
element.innerHTML="<span style='color: red'>this is lizi test</span>";
document.getElementsByName("username")[0].value = "li";
document.getElementsByTagName("p")[1].innerText = "this is second p";
document.getElementsByTagName("p")[1].style.color = "blue";
document.getElementsByClassName("ptest")[0].innerHTML="<span>this is p class test</span>";

</script>

</body>
</html>

 

上一篇:网页设置只能在手机微信客户端访问,禁止在电脑端访问包括微信电脑版


下一篇:js之动态创建元素-使用数组代替字符串拼接