Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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在a之后添加内容<;部门></部门>;当a<;span>;在那里面<;部门>;点击_Jquery - Fatal编程技术网

jQuery在a之后添加内容<;部门></部门>;当a<;span>;在那里面<;部门>;点击

jQuery在a之后添加内容<;部门></部门>;当a<;span>;在那里面<;部门>;点击,jquery,Jquery,在下面的代码中,我试图在包含的之后添加内容,此时单击中的 这就是地方: <div id="container"> <div class="h1" data-id="1">Teachers <span class="add" data-id="US01">Add New</span></div> <div class="h2" data-id="2">Who is your favorite Math tea

在下面的代码中,我试图在包含
之后添加内容,此时单击
中的

这就是地方:

<div id="container">

    <div class="h1" data-id="1">Teachers <span class="add" data-id="US01">Add New</span></div>
    <div class="h2" data-id="2">Who is your favorite Math teacher? <span class="add" data-id="US02">Add New</span></div>
        <br>
    <div class="h1" data-id="8">Restaurants <span class="add" data-id="US10">Add New</span></div>
    <div class="h2" data-id="9">Which is your favourtie restaurant in town? <span class="add" data-id="US20">Add New</span></div>

</div>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Side bar poll thingy</title>
<style type="text/css">
.hide {
    display: none;
}
.no-like {
    color: blue;
}
.first{
    display:block;
}
</style>

<script type="text/javascript" src="http://localhost/site/scripts/jQueryCore.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $(".add").click(function() {
        var idPri   = $(this).data("id");
        //var data = 'id='+idPri+'&sec='+idSec;
        console.log($(this).data('id'));
        $(this).after("<div class='newbox'>I'm new box by append</div>");



        if(idPri) {
            // ajax call
            $.ajax({
                type:"GET",
                url:"demo.php",
                data:data,
                dataType: 'json',
                beforeSend:function(html){
                    // To do later
                },
                success: function(callBack){

                },
                error: function(page_data){

                },
            });
        }
        return false;
    });
});
</script>
</head>
<body>

<div id="container">

    <div class="h1" data-id="1">Teachers <span class="add" data-id="US01">Add New</span></div>
    <div class="h2" data-id="2">Who is your favorite Math teacher? <span class="add" data-id="US02">Add New</span></div>
        <br>
    <div class="h1" data-id="8">Restaurants <span class="add" data-id="US10">Add New</span></div>
    <div class="h2" data-id="9">Which is your favourtie restaurant in town? <span class="add" data-id="US20">Add New</span></div>

</div>

</body>
</html>
使用
.parent()
方法:

$(this).parent("div").after("<div class='newbox'>I'm new box by append</div>");
$(this).parent(“div”).after(“我是新添加的框”);