js动态添加样式

  1. 方式一
 var doc = document, link = doc.createElement('link'), head = doc.getElementsByTagName('head')[0];
 link.href = path;
 link.rel = 'stylesheet';
 link.type = 'text/css';
 head.appendChild(link);
  1. 方式二
var doc = document, style = doc.createElement('style');
style.type = 'text/css';
style.innerHTML = '*{
                        margin: 0;
                        padding: 0;
                    }';

你可能感兴趣的:(js)