Template:带有 JavaScript 标头的代码段

From mediawiki.org
This page is a translated version of the page Template:Snippets with JavaScript header and the translation is 89% complete.

如何使用

你可以在资源加载器模块中使用这些片段。 这包括由核心生成的(例如从wiki页面生成的siteuser模块)和扩展中的。

参见手册:界面/JavaScript 以了解可以将这些代码片段加入你的网站的地方。

大多数片段假定是在文档准备好后执行的:对于这些情况,请确保您的代码中有一个文档就绪的包装器。 如果您还没有,请使用下面的内容:

$( function ()  {
	// 将代码片段粘贴在此处。
	// Paste as many as you like, only one "$( function () { ... } );" wrapper is needed!
} );
If the snippet processes the content part of wiki pages (the #mw-content-text element), you should use the 'wikipage.content' hook instead to make the snippet work after the page is updated asynchronously. See Gadget kitchen#Running code on page load for details.