Javascript 我可以从另一页加载表单吗?
JS是否可能从一个页面加载表单并在另一个页面中显示?例如,单击“/note/index”页面上的按钮,它会显示在“/note/new”中找到的表单,但我仍然在“/note/index”页面中 我知道我可以通过将所有html放在索引页中来实现这一点 进一步问题:是否建议按照我的要求行事 我当前的HTML for/notes/index.HTML.erbJavascript 我可以从另一页加载表单吗?,javascript,jquery,ruby-on-rails,ruby,Javascript,Jquery,Ruby On Rails,Ruby,JS是否可能从一个页面加载表单并在另一个页面中显示?例如,单击“/note/index”页面上的按钮,它会显示在“/note/new”中找到的表单,但我仍然在“/note/index”页面中 我知道我可以通过将所有html放在索引页中来实现这一点 进一步问题:是否建议按照我的要求行事 我当前的HTML for/notes/index.HTML.erb <script> $(function() { // contact form animations $('#new
<script>
$(function() {
// contact form animations
$('#newNote').click(function() {
$('#newNoteForm').fadeToggle();
})
$(document).mouseup(function (e) {
var container = $("#newNoteForm");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.fadeOut();
}
});
});
</script>
<!--New Note-->
<div class="row first-content-row">
<div class="col-xs-3">
<p><%= notice %></p>
<div class ="col-sm-offset-1 btn btn-lg btn-success">
<div id = "newNote">New Note</div>
</div>
</div><!--End col-->
</div><!--End row -->
<!-- This is the note that will be appearing -->
<div id="newNoteForm">
<h1>Add a new Note</h1>
<%= form_for @session_note, url: {action: "create"}, html: {class: "nifty_form"} do |f| %>
<%= f.text_area :note, size: "60x12" %>
<%= number_field(:session_note, :session_id) %>
<%= f.submit "Save" %>
<% end %>
</div>
$(函数(){
//联系人表单动画
$('#newNote')。单击(函数(){
$('#newNoteForm').fadeToggle();
})
$(文档).mouseup(函数(e){
var容器=$(“#newNoteForm”);
if(!container.is(e.target)//如果单击的目标不是容器。。。
&&container.has(e.target).length==0)/…或容器的后代
{
容器。淡出();
}
});
});
新注释
添加新注释
使用AJAX是可能的,如果您使用jquery,代码可能是:
$.get('/newpageurl/', function(data) {
var otherPage = $(data); //Get the other page dom as data
var otherPageForm = $(otherPage).find('form#myform'); // find the form
$('body').append('otherPageForm');// place the form in the current page
});
使用AJAX是可能的,如果您使用jquery,代码可能是:
$.get('/newpageurl/', function(data) {
var otherPage = $(data); //Get the other page dom as data
var otherPageForm = $(otherPage).find('form#myform'); // find the form
$('body').append('otherPageForm');// place the form in the current page
});