functioninitAll() { document.getElementById("redirect").onclick = initRedirect; } /* JavaScript 关键字 this 使脚本能够根据使用这个关键字的上下文将值传递给函数。在这个示例 中, this 是在一个由标签的事件触发的函数中使用的,所以 this 是一个链接对象。只需将 this 看 做一个容器. */ functioninitRedirect() { alert("We are not responsible for the content of pages outside our site"); window.location = this; returnfalse; }
/*在这个函数中,我们为页面上的每个按钮设置了 onclick 处理程序。因为在 HTML 中设置了 id 属性和 value 属性,所以可以使用 getElementById() 设置事件处理程序。如果有 value 属性,就可以使用 getElementByValue() 调用,那么就不必设置 id 属性。 */ }