什么'这行在javascript中的意思是什么

what's the line meaning in javascript?

本文关键字:意思 意思是 是什么 javascript 什么      更新时间:2023-09-26
  1. if (document.all)
  2. document.body.style.behavior='url(#default#homepage)';
  3. if (window.sidebar)

这些行在javascript中是什么意思?非常感谢。

不使用文档。全部:

if (document.all) {
   element = document.all[id];
else {
   element = document.getElementById(id);
}
  1. document.all是在InternetExplorer4中引入的,因为W3C DOM还没有标准化使用元素ID获取引用的方法。
    到IE 5问世时,document.getElementById((已经标准化,因此,IE 5包含了对它的支持。更多信息请点击此处。。

  2. document.body.style.behavior='url(#default#homepage)'用于在IE中将当前页面设置为主页。

  3. if (window.sidebar)是firefox的检查
document.all is used to check if the browser is IE

if (document.all):用于检查浏览器是否为IE,但请注意,这是一种糟糕的做法,因为它不再是一种好的测试方法。

if (window.sidebar):测试浏览器是否为Firefox。

编辑:当浏览器为IE时,document.body.style.behavior='url(#default#homepage)';最有可能用于设置主页。然而,它似乎不能很好地与Firefox和其他浏览器配合使用。

语句1尝试检测浏览器是否为IE,语句2是否使用IE-only API:behavior属性。

不过,document.all并不是IE独有的功能。它也存在于Chromium/Chrome和其他基于WebKit的浏览器上。

因此,语句1在IE&Chrome,但语句2仅适用于IE。