javascript - <paper-input> 或 <core-input> 元素上的 polymer focus()

标签 javascript polymer

有没有办法聚焦 core-input 或 paper-input 元素?

我想要实现的是:将光标设置为输入元素,以便用户可以开始输入。

这样他就不会在写之前被迫点击元素。

最佳答案

core-input 现在有一个 .focus() 方法,它委托(delegate)给内部的 focus()

来自 core-input.html 代码:

focus: function() {
    this.$.input.focus();
  }

这意味着在您自己的代码中您需要像下面这样调用它:

elem[0].focus()

在我自己的例子中,我从 timeout 调用 focus。在这种情况下,bindcore-input 正确使用this 所必需的:

$timeout(elem[0].focus.bind(elem[0]));

关于javascript - <paper-input> 或 <core-input> 元素上的 polymer focus(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24496590/

相关文章:

javascript - 为什么我的 watch 方法在 Vue 中不起作用

JavaScript - 纸张警报对话框后的 polymer : this. 拼接

javascript - 如何在 json 中存储多个值?

html - 包含表格单元格的 polymer 自定义元素?

javascript - 在 Polymer 中获取元素内容而不显示在页面上

javascript - 带有远程数据源的 Typeahead.js

javascript - 测试 Object.hasOwnProperty

javascript - 按钮初始化

javascript - AngularJS 在不同模块之间共享 Controller 中存储的数据

polymer - 使用 Polymer Paper-Slider 创建具有两个值的范围