我是Ember.js的新手.
我想在初始化后重点关注TextField(在sample,id =“text”)中)
但在准备功能中,不工作焦点方法…
我想在初始化后重点关注TextField(在sample,id =“text”)中)
但在准备功能中,不工作焦点方法…
<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>
解决方法
以下代码可以正常工作:
<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>