JQuery输入字段焦点在angularjs演示模式中

时间:2015-10-31 07:38:52

标签: javascript jquery html angularjs

我尝试应用url中显示的演示模式:

http://getbootstrap.com/javascript/
after "Varying modal content based on trigger button".

并且还使用HTML代码

<input name="email" type="email" id="email" />

...和javascript代码

$('#exampleModal').on('show.bs.modal', function (event) {
  var button = $(event.relatedTarget)
  var modal = $(this)
  modal.find('.modal-title').text('Log In')
  modal.find('.modal-body input').val("This Body..")
  $(this).find('#email').focus();//why it doesn't work????????
})

如何自动在电子邮件输入中设置焦点功能? 谢谢

1 个答案:

答案 0 :(得分:1)

使用shown.bs.modal代替show.bs.modal

尝试以下内容:

$('#exampleModal').on('shown.bs.modal', function (event) {
  var button = $(event.relatedTarget)
  var modal = $(this)
  modal.find('.modal-title').text('Log In')
  modal.find('.modal-body input').val("This Body..")
  $(this).find('#email').focus(); //now it will work
})