var spanElement = document.getElementById("mySpan");

  spanElement.style.cssText = "font-weight:bold;color:red;";

  这种方法在IE和大多数其他浏览器上都能很好地工作,只有Opera除外, 为了让代码能在所有当前浏览器上都可以移值,可以同时使用这两种方法,如下所示:

  var spanElement = document.getElementById("mySpan");

  spanElement.setAttribute("style","font-weight:bold;color:red;");

  spanElement.style.cssText = "font-weight:bold;color:red;";

相关文章:

  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2021-06-16
相关资源
相似解决方案