我有一个带有登录表单的视图,并且我试图在呈现视图后设置焦点。我试过这个,但没有奏效:
class App.Views.Login extends Backbone.View
template: template("login")
events:
"click button": "login"
render: ->
@$el.html @template(@)
@$el.find("#email").focus()
也试过这个;
class App.Views.Login extends Backbone.View
template: template("login")
events:
"click button": "login"
render: ->
@$el.html(@template(@)).ready =>
@$el.find("#email").focus()
添加了路由器以显示如何将 Login 附加到 DOM:
class App.Routers.App extends Backbone.Router
initialize: ->
chrome = new Spokely.Views.Chrome el: $("#app")
chrome.render()
@mainEl = $("#main")
routes:
"": "index"
"ad/:id": "show"
"about": "about"
"login": "login"
"signup": "signup"
login: ->
view = new Spokely.Views.Login()
@mainEl.html view.render().el
我错过了什么?