本文整理匯總了TypeScript中index.dom類的典型用法代碼示例。如果您正苦於以下問題:TypeScript dom類的具體用法?TypeScript dom怎麽用?TypeScript dom使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了dom類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: testDom
function testDom() {
const obs = observable("grain");
const isValid = observable(false);
return [
dom('div#test1',
input(obs, {}, {type: 'text', placeholder: 'Your name...'}),
),
dom('div#test2',
input(obs, {isValid}, {type: 'email', placeholder: 'Your email...'}),
' isValid: ', dom('b', dom.text((use) => String(use(isValid)))),
),
dom('div#test3',
input(obs, {onInput: true}, {type: 'text'}),
),
"Current value: ", dom.text(obs),
];
}
示例2: dom
dom('input#test_value', {type: 'text'}, dom.prop('value', value),
dom.on('input', (e, elem) => value.set((elem as HTMLInputElement).value))),
),
textarea = dom('textarea', {rows: "10"}, choices.get().join("\n"),
dom.on('blur', parseChoices),
) as HTMLTextAreaElement,
dom('div',
dom('input', {type: 'button', value: 'Update'}, dom.on('click', parseChoices)),
),
),
dom('div#test_array',
select(value, ["apple", "cherry", "tomato", "orange"]),
),
dom('div#test_num',
select(numValue, numChoices),
dom('div', "Current value:", dom('br'),
dom('input#test_num_value', {type: 'text', size: "6"}, dom.prop('value', numValue),
dom.on('input', (e, elem) => {
const val = (elem as HTMLInputElement).value;
const n = parseFloat(val);
if (!isNaN(n)) { numValue.set(n); }
})),
" type: ",
dom('b#test_num_type', dom.text((use) => String(typeof use(numValue)))),
),
),
];
}
dom.update(document.body, testDom());