@$el.html(@template())
@$('an_input').val('2') # ---> this works
@$('selector').prop('checked', true) # ---> does not work
@$el.html(@template())
@$('an_input').val('2') # ---> this works
setTimeout( ->
@$('selector').prop('checked', true) # ---> works!
1000
)
有人知道为什么吗?
fiddle :http://jsfiddle.net/EC49U/
最佳答案
在正常情况下确实可以工作。在您的情况下,选择器在 1 秒后才能找到您要定位的元素。 这是一个没有超时的工作示例: http://jsfiddle.net/gouegd/zXGVD/
请注意,我使用checked=“checked”而不是true,我认为这更符合HTML 标准。
$('#car').prop('checked', "checked")
关于javascript - 为什么 Backbone 中的 checkbox 需要超时才能被选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15115662/