twitter-bootstrap Bootstrap - 在模式窗口上设置文本框值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16227049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap - Set textbox value on modal window
提问by Sushanth --
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.
我试图在我的模式中绑定事件“show”,但在显示时没有任何反应。
这是应该可以工作的代码。
未显示警报。
<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>
回答by Sushanth --
you need to encase the code inside DOM ready eventif your script is in the header section.
DOM ready event如果您的脚本位于标题部分,则需要将代码封装在其中。
$(function() {
$('#myModal').bind('show',function(){
alert('howdy');
$("#nome").val('bosta');
});
});
回答by Julian
This answer didn't work for me but this one did;
这个答案对我不起作用,但这个答案对我有用;
$("#mymodal #mymodal-label").html("My New Title");

