我希望能够将焦点设置为一个textarea,因为鼠标点击不在该任务区域。在一个应用程序应用程序中设置焦点
作为一个最小的例子,假设我从一个文本开始,如果点击它,它会被替换为一个文本字段。
<script type="text/x-handlebars">
{{#if isActive}}
{{view Ember.TextField}}
{{else}}
<p {{action foo}}> Click Here to Enter text </p>
{{/if}}
</script>
与
App.ApplicationController = Ember.Controller.extend({
isActive: false,
foo: function(){
this.set("isActive", true);
}
});
这个工程创建的点击文本字段,但该文本区域(这需要不给焦点控制器:我可以通过把手脚本实现这一目标第二次点击才能够实际输入文字)。
有没有一个很好的方法来达到这个目的?我可以通过在模板中设置一个ID并使用jquery来选择它,但这看起来不够雅致。
好的建议。对其他人的说明,此属性在Internet Explorer版本<10中不起作用。[Autofocus Attribute](http://www.w3schools.com/tags/att_input_autofocus.asp) – Scott