码迷,mamicode.com
首页 > Web开发 > 详细

JS——DOM操作(操纵元素属性【getAttribute、setAttribute...】)

时间:2019-05-28 17:06:34      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:dev   http   删除   元素属性   attribute   fun   bsp   spl   device   

常见元素操作:

(1):oDiv.style.display=‘block‘;

(2):oDiv.style[‘display‘]=‘block‘;

(3):DOM方式  【看下面列举↓↓↓↓】

 

DOM方式操作元素属性

1》获取:getAttribute(‘ 名称 ‘)

2》设置:setAttribute(‘ 名称 ‘,‘ 值 ‘)

3》删除:removeAttribute(‘ 名称 ‘)

 

详细看如下代码:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 6     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 7     <title>Document</title>     
 8     <script>
 9         window.onload=function(){
10             var oTxt=document.getElementById(txt);
11 
12             oTxt.setAttribute(value,444);   //设置文本框的值为‘444’
13             
14             alert(oTxt.getAttribute(id));     //获取文本框的id值  即:txt
15 
16             oTxt.removeAttribute(id);         //删除文本框的id值
17         }
18     </script>
19 </head>
20 <body>
21     <input type="text" id="txt">
22 </html>

 

JS——DOM操作(操纵元素属性【getAttribute、setAttribute...】)

标签:dev   http   删除   元素属性   attribute   fun   bsp   spl   device   

原文地址:https://www.cnblogs.com/ytraister/p/10938200.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!