Bootstrap-在模式窗口上设置文本框值 [英] Bootstrap - Set textbox value on modal window

查看:72
本文介绍了Bootstrap-在模式窗口上设置文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将事件'show'绑定到我的模式中,但显示时没有任何反应.
这是应该起作用的代码.
该警报未显示.

I've tried to bind the event 'show' in my modal but nothing happens when it's shown.
Here's the code that was supposed to work.
The alert is not beeing displayed.

<script type="text/javascript" charset="utf-8">
            $('#myModal').bind('show',function()
            {
                alert('howdy');
                $(".modal-body #nome").val('bosta');
            });
        </script>


模态窗口代码:


Modal window code:

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel">Minha Conta</h3>
            </div>



            <div class="modal-body">
                <form class="form-horizontal" id="mConta">
                    <div class="control-group">
                        <label class="control-label">Nome</label>
                        <div class="controls">
                            <input id="nome" name="nome" type="text" placeholder="" class="input-xlarge" required="">

                        </div>
                    </div>

                </div>
            </form>



            <div class="modal-footer">
                <button class="btn" data-dismiss="modal" aria-hidden="true">Cancelar</button>
                <button type="submit" class="btn btn-primary">Salvar</button>
            </div>
        </div>

推荐答案

如果脚本位于 header部分中,则需要将代码包含在DOM ready event中.

you need to encase the code inside DOM ready event if your script is in the header section.

$(function() {
  $('#myModal').bind('show',function(){
      alert('howdy');
      $("#nome").val('bosta');
  });
});

这篇关于Bootstrap-在模式窗口上设置文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆