当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript dom.on方法代码示例

本文整理汇总了TypeScript中index.dom.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript dom.on方法的具体用法?TypeScript dom.on怎么用?TypeScript dom.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在index.dom的用法示例。


在下文中一共展示了dom.on方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: testDom

function testDom() {
  const value = observable("apple");
  const choices = obsArray<IOption<string>>(["acorn", "apple", "orange", "papaya"]);

  let textarea: HTMLTextAreaElement;

  function parseChoices() {
    choices.set(textarea.value.trim().split("\n"));
  }

  const numChoices: Array<IOptionFull<number>> = [
    {value: 1.5, label: "A1"},
    {value: 2.1, label: "B2", disabled: true},
    {value: 3.9, label: "C3"},
  ];
  const numValue = observable(numChoices[2].value);

  return [
    dom('div#test_main',
      select(value, choices, {defLabel: "Select a fruit:"}),
      dom('div', "Current value: ",
        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)))),
      ),
    ),
  ];
}
开发者ID:gristlabs,项目名称:grainjs,代码行数:49,代码来源:index.ts


注:本文中的index.dom.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。