Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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
jQuery在元素之后加载ajax_Jquery_Html_Ajax - Fatal编程技术网

jQuery在元素之后加载ajax

jQuery在元素之后加载ajax,jquery,html,ajax,Jquery,Html,Ajax,html代码块: index.php html块: <div class="row"> <button id="addoption" type="submit">add</button> </div> 它可以添加但也可以删除div.row。(它将div.row替换为div#optionform) 我只想在div.row之后添加div#optionformhtml块 我怎么做 我想要这个: <div class="row">

html代码块:

index.php html块:

<div class="row">
    <button id="addoption" type="submit">add</button>
</div>
它可以添加但也可以删除
div.row
。(它将div.row替换为
div#optionform

我只想在
div.row
之后添加
div#optionform
html块

我怎么做

我想要这个:

<div class="row">
    <button id="addoption" type="submit"></i>add</button>
</div>
<div class="well" id="optionform" >hello</div>

添加
你好

在没有看到代码的情况下,我不能完全确定external.php是如何设置的,因此我无法告诉您如何获取这些数据

<script type="text/javascript">
var optionscount=0;
    $( "#addoption" ).click(function() {
       $( "#options" ).append("<div class=\"well\" id=\"optionform("+optionscount+"\">hello</div>");
    });
</script>

<div class="row" id="options">
    <button id="addoption" type="submit"></i>add</button>
</div>

var optionscount=0;
$(“#添加选项”)。单击(函数(){
$(“#选项”).append(“hello”);
});
添加

正如@Alok Mishra提到的,您可以使用
.append()
在指定元素的下面添加元素。您使用它的方式如下:

$('#parent').append( $('#child') );
所以你可以写:

$('#addoption').click(function(){
  $(document).load("external.php #optionform");
  $('.row').parent().append( $('#optionform') );
})

注意:我将
external.php
拼写为onononly
l
。我认为这是一个从酸涩的一面拼写错误。

append不起作用。它也可以替代

最后我这样解决了:

$('#addoption').on('click',function(){
        var response;
        $.ajax({ type: "GET",   
            url: "externall.php",   
            async: false,
            success : function(text)
            {
                response= text;
            }
        });
        $(this).parent().after(response);
    });

您是否在jQuery中尝试了.append()方法?它不会删除现有元素,但会在所选父元素的底部插入新内容。您的有效内容无效。你有一个结束的
,但没有开始的。嗨,Elize,你想在点击按钮后添加值吗?@AalokMishra,你有没有试着看看API
.after()
做了什么?他想让他的表单离开div行,你的代码将表单插入div。但是他想在下面/后面添加内容,不要像孩子一样感谢你的建议。我忘了带家长了(;)请注意,
async
已被弃用,因此最好存储
var$parent=$(this).parent()
并将
$parent.after(text)放在后面在您的
成功中
。。不需要响应变量,也不需要异步too他想加载
external.php
而不仅仅是一些HTML。并且希望它在
div.row
之后,而不是在内部。
$('#parent').append( $('#child') );
$('#addoption').click(function(){
  $(document).load("external.php #optionform");
  $('.row').parent().append( $('#optionform') );
})
$('#addoption').on('click',function(){
        var response;
        $.ajax({ type: "GET",   
            url: "externall.php",   
            async: false,
            success : function(text)
            {
                response= text;
            }
        });
        $(this).parent().after(response);
    });