Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我可以从另一页加载表单吗?_Javascript_Jquery_Ruby On Rails_Ruby - Fatal编程技术网

Javascript 我可以从另一页加载表单吗?

Javascript 我可以从另一页加载表单吗?,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

JS是否可能从一个页面加载表单并在另一个页面中显示?例如,单击“/note/index”页面上的按钮,它会显示在“/note/new”中找到的表单,但我仍然在“/note/index”页面中

我知道我可以通过将所有html放在索引页中来实现这一点

进一步问题:是否建议按照我的要求行事

我当前的HTML for/notes/index.HTML.erb

<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
});