本文介绍了使用emberjs进行初始化后如何集中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚接触到Ember.js。我想在初始化后重点关注TextField(在sample,id =text)中,
但是在ready函数中,不工作focus方法...
< body>
<! - 库加载 - >
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js>< / script>
< script>!window.jQuery&& document.write(unescape('%3Cscript src =js / libs / jquery-1.6.1.min.js%3E%3C / script%3E'))< / script>
< script src =http://cloud.github.com/downloads/emberjs/ember.js/ember-0.9.5.min.js>< / script>
< script type =text / x-handlebars>
{{查看Em.TextField id =text}} //要集中它。
< / script>
< script type =text / javascript>
var App = Em.Application.create();
App.ready = function(){
$('#text')。focus(); //不工作
}
< / script>
< / body>
解决方案
以下代码可以正常工作:
< script type =text / x-handlebars>
{{view App.TextField id =text}} //要集中它。
< / script>
< script type =text / javascript>
var App = Em.Application.create();
App.TextField = Em.TextField.extend({
didInsertElement:function(){
this。$()。focus();
}
});
< / script>
I'm new to Ember.js.I want to focus on TextField(in sample, id="text") after initialization,but in ready function, doesn't work focus method...
<body>
<!-- library load -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.6.1.min.js"%3E%3C/script%3E'))</script>
<script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-0.9.5.min.js"></script>
<script type="text/x-handlebars">
{{view Em.TextField id="text"}} // want to focus it.
</script>
<script type="text/javascript">
var App = Em.Application.create();
App.ready = function() {
$('#text').focus(); // does'nt work.
}
</script>
</body>
解决方案
The following code does work:
<script type="text/x-handlebars">
{{view App.TextField id="text"}} // want to focus it.
</script>
<script type="text/javascript">
var App = Em.Application.create();
App.TextField = Em.TextField.extend({
didInsertElement: function() {
this.$().focus();
}
});
</script>
这篇关于使用emberjs进行初始化后如何集中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!