js dynamically create link

Compatibility of jquery writing is good

<script> 

  var link = document.createElement('link');

  $(link).attr('rel','stylesheet');

  $(link).attr('type','text/css');

  $(link).attr('href','/platform/static/largedata/desktop/css/index.css');

  document.getElementsByTagName('head')[0].appendChild(link)

</script> 

It is also possible to write the following

<script>

  var link = document.createElement('link');

  link.setAttribute('rel','stylesheet');

  link.setAttribute('type','text/css');

  link.setAttribute('href','/platform/static/largedata/desktop/css/index.css');

  document.getElementsByTagName('head')[0].appendChild(link)

</script> 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326747738&siteId=291194637