zoukankan      html  css  js  c++  java
  • 元素属性监听

    做一个事件On_Attr_Change,监听元素属性的变化,以便属性变化的时候作出处理

    <html>
        
        <head>
            <script>
                function AddListeners() {
                    var elemToCheck = document.getElementById("myDiv");
                    if (elemToCheck.addEventListener) { // Firefox, Opera and Safari
                        elemToCheck.addEventListener('DOMAttrModified', OnAttrModified, false);
                    }
                    else if (elemToCheck.attachEvent) { // Internet Explorer
                        elemToCheck.attachEvent('onpropertychange', OnAttrModified);
                    }
                }
    
                function OnAttrModified(event) {
                    var txt = "";
                    if (event.attrChange) {
                        // Firefox, Safari, Opera
                        txt += "The element: " + event.target;
                        txt += "\nproperty: " + event.attrName;
                        txt += "\noriginal value: " + event.prevValue;
                        txt += "\n changed to: " + event.newValue;
                    }
                    else {
                        // Internet Explorer
                        txt += "The element: " + event.srcElement.tagName;
                        txt += "\nproperty: " + event.propertyName;
    
                        var elem = event.srcElement;
                        txt += "\nchanged value: " + elem.attributes[event.propertyName].value;
                    }
                    alert(txt);
                }
    
                function ChangeDDD() {
                    var div = document.getElementById("myDiv");
                    div.setAttribute("ddd", "New Attribute");
                }
            </script>
        </head>
        
        <body onload="AddListeners ();">
            <button onclick="ChangeDDD ();">Change ddd Attribute!</button>
            <div id="myDiv" ddd="Old Attribute">divdivdivdivdivdivdivdiv</div>
        </body>
    
    </html>
  • 相关阅读:
    Python find()方法
    Python expandtabs()方法
    RGB-D对红外热像仪和毫米波雷达标定
    ADAS虚拟车道边界生成
    3D惯导Lidar SLAM
    语义分割改进:通过视频传播和标签松弛
    YOLOv4:目标检测(windows和Linux下Darknet 版本)实施
    tensorflow-yolov4实施方法
    3D惯导Lidar仿真
    YOLOv4实用训练实践
  • 原文地址:https://www.cnblogs.com/fxair/p/2321719.html
Copyright © 2011-2022 走看看