我想创建一个导航栏按钮,该按钮调用包含表单的引导模式。我在https://gist.github.com/havvg/3226804找到了一个要点,我正在尝试使其适应我的需要。我还没有完成脚本的 ajax 部分的填写,但我注意到模式没有激活。我想按下导航栏上的按钮并弹出模态表单。我究竟做错了什么?
<div class="hide fade modal" id="rating-modal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">button</button>
<h2>Your Review</h2>
</div>
<div class="modal-body">
<!-- The async form to send and replace the modals content with its response -->
<form class="form-horizontal well" id="modalForm" data-async data-target="#rating-modal" action="AjaxUpdate/modal" method="POST">
<fieldset>
<!-- Form Name -->
<legend>modalForm</legend <!-- Text input-->
<div class="control-group">
<label class="control-label" for="old">Old password</label>
<div class="controls">
<input id="old" name="old" type="text" placeholder="placeholder" class="input-xlarge">
<p class="help-block">help</p>
</div>
</div>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="new">New password</label>
<div class="controls">
<input id="new" name="new" type="text" placeholder="placeholder" class="input-xlarge">
<p class="help-block">help</p>
</div>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer"> <a href="#" class="btn" data-dismiss="modal">Cancel</a>
</div>
</div>
<script src='js/jquery.js'></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
// $('form[data-async]').live('submit', function(event) {
$('#modalForm').on('submit', function (event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
success: function (data, status) {
$target.html(data);
}
});
event.preventDefault();
});
});
</script>