2 回答
TA贡献1875条经验 获得超5个赞
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="na_style_8.css">
</head>
<body>
<div id="box"></div>
</body>
</html>
Javascript
<script type="text/javascript">
var figure = document.createElement('figBox'),
loadStylesheet = (stylesheet) => {
stylesheetElement.setAttribute('href', stylesheet + '?' + new Date().getTime());
},
stylesheetElement = document.querySelector('link[href="na_style.css"]');
figure.setAttribute('id', 'styleThumbs');
document.getElementById('box').appendChild(figure);
for (var i = 0; i < 4; i++) {
var sheetImage = document.createElement('sheetImage');
sheetImage.setAttribute('src', 'na_small_num.png');
sheetImage.setAttribute('alt', 'na_style_' + [i] + '.css');
// Populate figBox with created sheetImage
figure.appendChild(sheetImage);
// Add click event listener to sheetImg element
sheetImage.addEventListener('click', (event) => {
// Load stylesheet with anonymous function
loadStylesheet(event.target.getAttribute('alt'));
});
}
</script>
添加回答
举报