小编Ala*_*Kid的帖子

removeAttribute() 不适用于 DOM

为什么不removeAttribute()删除以下代码中的任何内容:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>test</title>
</head>
<body>
    <div id="myDiv">
        Element with style.
    </div>
    <br />
    <br />
    <button onclick="DelStyle()">
        Remove the style attribute from the element
    </button>
    <script type="text/javascript">
        function DelStyle() {
            var div = document.getElementById("myDiv");
            console.log(div)
            div.style.border = 'solid #3B3B3D 1px';
            console.log(div)
            div.removeAttribute("style");
            console.log(div)
        }
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

javascript dom

5
推荐指数
1
解决办法
3万
查看次数

鼠标按下.传播给兄弟姐妹event.targets

图片

我有2个带有'position absolute'的兄弟节点,它们都处理mousedown事件.当我点击'div 2'的透明区域(在图片上)时,如何触发'div 1'的处理程序

javascript siblings mousedown

5
推荐指数
1
解决办法
2622
查看次数

2以下自调用功能不起作用

这段代码有什么问题?

function test() {

   (function(){
      console.log('1')  
   })()

   (function(){
      console.log('2')
   })()
}

test()
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/VvaCX/

javascript self-invoking-function

1
推荐指数
1
解决办法
80
查看次数