JQuery引导模式窗口以某种方式重载/清除Ruby on Rails项目中的父字段
JQuery Bootstrap Modal Window somehow reload/clears the parent fields in Ruby on Rails project
我的问题是,当点击OK在模态窗口,去javascript函数在模态会重新加载或清除父字段?
下面是用例:1. 在父名称表单输入中输入名称字符串2. 点击测试模态按钮3.出现一个模态窗口4. 点击模态窗口"OK"按钮。(有了取消按钮,这不是问题)5. 清除父名称输入。可能父节点被重新加载了
我已经创建了一个简单的rails项目与生成的脚手架名称:字符串。没什么特别的,只是启用了bootstrap js和css。https://github.com/axilaris/bootstrapmodal/blob/master/app/assets/javascripts/application.jshttps://github.com/axilaris/bootstrapmodal/blob/master/app/assets/stylesheets/application.css
然后,我将这段代码插入_form.html。你可以在这里查看: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>
就是这些,它很灵活,我可以隐藏,不隐藏,做一些事情
相关文章:
- Ruby on Rails javascript getting truncated
- 在ruby on rails中使用jquery getJSON获取数据
- Ruby On Rails应用程序与angularJS关于AJAX
- Angular JS/Rube-on-Rails-控制器未识别错误
- ruby on rails:用于不同页面的选项卡
- Ruby On Rails Ajax 提交提交两次
- Ruby on Rails - 引导旋转木马按钮不起作用
- 按索引迭代数组时,单击提交按钮Ruby on Rails
- 如何将.js从视图移动到单独的资产 - Ruby On Rails
- 如何在Ruby on Rails中集成Arbor.js
- geolocation with javascript and ruby on rails
- Ruby on Rails 4:在 Rails Web 应用程序中添加 Javascript 文件时遇到问题
- Window.onload 未被调用 [Ruby on Rails] [Vanilla Javascript]
- Rails应用程序中的每个javascript文件都需要.on('page:change',初始化)吗?
- 如何在Ruby on Rails会话过期时重新加载或刷新页面
- 重命名上传的文件Ruby On Rails
- Ruby on Rails - grouped_collection_select error
- 带有jquery.min.map的Ruby on Rails:未能加载资源状态406
- Ruby on rails-更新ajax的PUT方法
- Rails on iOS - action "show"无法在:method =>:删除