本文整理匯總了TypeScript中global.document類的典型用法代碼示例。如果您正苦於以下問題:TypeScript document類的具體用法?TypeScript document怎麽用?TypeScript document使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了document類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: addCssWarning
export default function addCssWarning() {
const warning = document.createElement('h1');
warning.textContent = 'CSS rules are not configured as needed';
warning.className = 'css-rules-warning';
warning.style.color = 'red';
document.body.insertBefore(warning, document.body.firstChild);
}
示例2: constructor
constructor(private readonly config: Config) {
this.buffer = [];
this.handler = null;
window.addEventListener('message', this.handleEvent.bind(this), false);
document.addEventListener('DOMContentLoaded', () => this.flush());
// Check whether the config.page parameter has a valid value
if (config.page !== 'manager' && config.page !== 'preview') {
throw new Error(`postmsg-channel: "config.page" cannot be "${config.page}"`);
}
}
示例3: getWindow
private getWindow(): Window {
if (this.config.page === 'manager') {
// FIXME this is a really bad idea! use a better way to do this.
// This finds the storybook preview iframe to send messages to.
const iframe = document.getElementById('storybook-preview-iframe');
if (!iframe) {
return null;
}
return iframe.contentWindow;
}
return window.parent;
}
示例4: createElement
const getElement = (id: string, code: string) => {
const found: Element = document.querySelector(`[id="storybook-addon-resource_${id}"]`);
return { element: found || createElement(id, code), created: !found };
};
示例5:
const createElement = (id: string, code: string): HTMLDivElement => {
const element: HTMLDivElement = document.createElement('div');
element.setAttribute('id', `storybook-addon-resource_${id}`);
element.innerHTML = code;
return element;
};