美文网首页
3.属性节点

3.属性节点

作者: 若愚同学 | 来源:发表于2018-06-12 22:11 被阅读0次
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="index.js"></script>

<style type="text/css">
    
    .myclass{
        background-color: pink;
    }
    
    
    
</style>

</head>
<body>
    
    <!-- <form action="" method="get" name="form1" id="form" eat="吃"></form> -->
    
    <select multiple="multiple" size="5" id="sel">
        <option>西施</option>
        <option>貂蝉</option>
        <option>杨玉环</option>
        <option>王昭君</option>
    </select>
    
    
    <button class="myclass" id="btn">按钮</button>
    <button id="btn2" style="background-color: green">按钮</button>
    
    <input type="text" id="input" value="张三">
</body>
</html>
JS:
window.onload = function(){
    //var ele = document.getElementById("form");

    //原始属性
    //获取属性值
/*  var name1 = ele.name;
    console.log(name1);
    var name2 = ele.getAttribute("name");
    console.log(name2);*/

    //设置属性值
/*  ele.name = "哈哈哈";
    console.log(ele.name);
    ele.setAttribute("name","hahah");
    console.log(ele.name);*/

    //自定义属性
/*  console.log(ele.eat);
    console.log(ele.getAttribute("eat"));
    
    ele.eat = "喝";
    console.log(ele.getAttribute("eat"));
    ele.setAttribute("eat","喝");
    console.log(ele.getAttribute("eat"));*/
    
    /*
     *操作属性名和默认属性值相同的属性. 如:checked,selected
     *在Dom操作 checked 或者 selected 对应属性值是true false
     *不用true,随便用一些字符也能有选中效果,因为在js中,为fasle的一共有6个常量,前一天的内容
     */
    var ele = document.getElementById("sel");
    //ele.firstChild.nextSibling.selected = "2";结果也能选中
    ele.firstChild.nextSibling.selected = true;
    
    //操作class属性-->属性名为:className
    var btn = document.getElementById("btn");
    //获取属性名
    console.log(btn.className);
    
    //获取btn2中style的background-color
    /*
     操作style的属性.如:background-color  ---> style[“background-color”]
     style对象.backgroundColor 
     */
    var btn2 = document.getElementById("btn2");
    console.log(btn2.style["background-color"]);
    console.log(btn2.style.backgroundColor);
    
    
    //只读操作操作readonly属性:readonly--->readOnly
    var input = document.getElementById("input");
    input.readOnly=true;
};

相关文章

  • 3.属性节点

    HTML: JS:

  • 3.节点的属性

    1.节点的属性-nodeType 2. 节点的属性 – nodeName、tagName 3.节点的属性 - in...

  • DOM相关概念

    饥人谷_李栋 1.节点的属性2.节点的方法3.节点的集合 一、node属性 nodeName://节点的名字 no...

  • Day23——jQuery

    一、导入jQuery 二、节点操作 1. 获取节点 2. 创建节点 3. 添加节点 4. 删除节点 三、属性操作 ...

  • javaScript:DOM常用操作

    1. 元素选择 2. 创建节点 3.节点关系 4. 属性操作 5. 表单操作

  • JS/DOM节点操作

    1.访问节点 2.生成节点 3.添加节点 4.复制节点 5.删除节点 6.修改文本节点 7.属性操作 8.查找节点...

  • [Vue]createElement参数

    函数模板 二、函数模板各部分含义 1.'div':html节点 2.{}:节点的属性 详细属性: 3.[]:1的h...

  • DOM常用方法

    1.访问/获取节点 2.创建节点/属性 3.添加节点 4.复制节点 5.删除节点 注意:为了保证兼容性,要判断元素...

  • 扒一扒DOM

    目录1.什么是DOM2.节点的概念3.节点的属性和方法4.Element对象的属性和方法5.Attribute对象...

  • day03

    A.今天你学到了什么 1.添加子元素节点方法 2.获取父元素节点 3.界面删除父节点 4.更改子节点属性 5.获取...

网友评论

      本文标题:3.属性节点

      本文链接:https://www.haomeiwen.com/subject/tpxdeftx.html