Traversing get id html page for all elements

Because to write a rights management system, accurate to each tag. Previously used is to give each tag plus right judgment code. But I feel this way too much trouble and backward, automatically scan each tag to the id and saved to the database to make when the page loads. Control by id. Research under the codes are as follows:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="1">1111111</div>
<button id="2">222222222</button>
<input id="3" type= "text" value = "33 is" /> 

</ body > 
< Script type = "text / JavaScript" > 
  
    // get the current page, all content objects 
    var _docc = window.document.all; 
    the console.log (_docc); 
    // iterate each object 
    for ( var I = 0 ; I < _docc.length; I ++ ) {
         var _dc = _docc [I]; 
        the console.log ( " window.document.all = " + _dc);
         // each node node id acquired
        var id = _dc.getAttributeNode("id");
        console.log("getAttributeNode=");
        console.log(id);
        // 当前标签的id的值
        var id = _dc.getAttribute("id");
        console.log("getAttribute="+id);
    }



</script>
</html>

Result: you can see a will traverse all the elements id value out of body, you may need to optimize the code according to their own

Guess you like

Origin www.cnblogs.com/gynbk/p/11595914.html