Js, jqurey, html questions

Asked 2 years ago, Updated 2 years ago, 42 views

$(function() {
$.getJSON("userList.do",function(u){

         $.each(u, function(i,e){

                var div = $("<div></div>");
                var delBtn = $("<Button>Withdraw</Button>");

                $(div).html()
                $(div).append(delBtn);
                $("#tel").append(div);

                $(delBtn).click(function() {
                    $.ajax({
                        url:"",
                        data:id,
                        success:function(data)
                        {
                            var re = eval("("+data+")")
                            if(re=='success')
                            {
                                alert("ok");
                            }
                            else
                            {
                                alert("nono");
                            }
                        }
                    })
                })


                var tr = $("<tr></tr>");
                var td1 = $("<td></td>").html(e.id);
                var td2 = $("<td></td>").html(e.nickname);
                var a = $("<a>"+e.phone+"</a>");

                $(a).click(function(){
                    $.getJSON("",function(data){
                        $("#container").html("");
                        $("#container").append("<h2 style='color: white;'> Member list</h2><divid='User'>");
                    });
                });
                var td3 = $("<td></td>").html("<a href=''>"+e.phone+"</a>");
                var td4 = $("<td></td>").html(e.email);
                var td5 = $("<td></td>").html(e.point);
                $(tr).append(td1,td2,td3,td4,td5);
                $("#tb").append(tr);

                });
        });});

I want to have a button next to my ID, but as td is added, button is added separately. Please save the beginner

javascript jquery java html

2022-09-21 22:05

1 Answers

I don't think you're using the button stored in the a variable after defining it...?

var td3 = $("<td></td>").html("<a href=''>"+e.phone+"</a>");

Try changing this part like this.

var td3 = $("<td></td>").append(a);

And "ID" is stored in td1, so don't you have to change td2 and td3 to get "Button next to ID"?


2022-09-21 22:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.