[英]JQuery Bootstrap Modal Window somehow reload/clears the parent fields in Ruby on Rails project
我的问题是在模态窗口中单击“确定”时,模态中的javascript函数将重新加载或清除父字段?
这里是用例:1.在父名称形式输入中输入名称字符串2.单击测试模态按钮3.出现模态窗口4.单击模态窗口“确定”按钮。 (使用“取消”按钮,这不是问题)5.清除了父名称输入。 可能是父母被重装了。
我用生成的支架Post name:string创建了一个简单的Rails项目。 没什么特别的,但我只是启用了bootstrap js和CSS。 https://github.com/axilaris/bootstrapmodal/blob/master/app/assets/javascripts/application.js https://github.com/axilaris/bootstrapmodal/blob/master/app/assets/stylesheets/application.css
然后,我将此代码插入_form.html.erb,您可以在此处查看: https : //github.com/axilaris/bootstrapmodal/blob/master/app/views/posts/_form.html.erb
<div id="windowCreateInvoiceProductDialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="windowTitleLabel" aria-hidden="true">
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal">×</a>
<h3>Please enter a new product</h3>
</div>
<div class="modal-body">
<div class="divDialogElements">
Code:<input class="xlarge" id="xlInput" name="modal_code" type="text" />
<br>
Name:<input class="xlarge" id="xlInput" name="modal_name" type="text" />
<br>
Description:<input class="xlarge" id="xlInput" name="modal_desc" type="text" />
<br>
Price:<input class="xlarge" id="xlInput" name="modal_price" type="text" />
</div>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
<a href="#" class="btn btn-primary" onclick="okClicked ();">OK</a>
</div>
</div>
<div class="divButtons">
<a data-toggle="modal" href="#windowCreateInvoiceProductDialog" class="btn btn-primary btn-large">Test Modal Button</a>
</div>
<script>
$(document).ready(function() {
$('#windowCreateInvoiceProductDialog').bind('show', function () {
// document.getElementById ("xlInput").value = document.title;
});
});
function okClicked () {
$('#windowCreateInvoiceProductDialog').modal('hide');
// document.title = document.getElementById ("xlInput").value;
// closeDialog ();
};
</script>
找到了答案!
代替这个
<a href="#" class="btn btn-primary" >OK</a>
用这个替换
<button type="button" class="btn btn-primary" onclick="okClicked ();">Save changes</button>
这就是它的全部,而且它的灵活性很强,我可以隐藏,不能隐藏并做某事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.