欧博娱乐Create dynamic id in html

//<![CDATA[ /* js/external.js */ var doc, html, bod, nav, mobile, M, I, S, Q, special, unspecial; // for use on other loads addEventListener('load', function(){ doc = document; html = doc.documentElement; bod = doc.body; nav = navigator; mobile = nav.userAgent.match(/Mobi/i) ? true : false; M = function(tag){ return doc.createElement(tag); } I = function(id){ return doc.getElementById(id); } S = function(selector, within){ var w = within || doc; return w.querySelector(selector); } Q = function(selector, within){ var w = within || doc; return w.querySelectorAll(selector); } special = function(str){ return str.replace(/&/g, '&amp;').replace(/'/g, '&apos;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); } unspecial = function(str){ return str.replace(/&amp;/g, '&').replace(/&apos;/g, "'").replace(/&quot;/g, '"').replace(/&lt;/g, '<').replace(/&gt;/g, '>'); } var out = I('output'), arr = [['ab', 'cd'], ['ef', 'gh'], ['ij', 'kl', 'mn', 'op'], ['qr', 'st'], ['uv', 'wx', 'yz']], outerDiv, innerDiv; arr.forEach(function(a){ outerDiv = M('div'); outerDiv.className = 'demo'; a.forEach(function(v){ // no need for `special` in this case but you may have special characters to escape innerDiv = M('div'); innerDiv.innerHTML = special(v); outerDiv.appendChild(innerDiv); }); output.appendChild(outerDiv); }); }); // end load //]]> /* css/external.css */ *{ box-sizing:border-box; } .demo{ border: 1px solid green; padding: 10px; margin: 20px; } <!DOCTYPE html> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> <head> <meta charset='UTF-8' /><meta content='width=device-width, height=device-height, initial-scale:1' /> <title>Test Template</title> <link type='text/css' href='css/external.css' /> <script type='text/javascript' src='js/external.js'></script> </head> <body> <div></div> </body> </html>

2025-07-29 03:57 点击量:3