CodeLab
Show Output
 
xxxxxxxxxx
23
 
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="utf-8">
5
<title>jQuery Add LI to an Existing UL</title>
6
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
7
<script>
8
$(document).ready(function(){
9
    $("button").click(function(){
10
        $("#menu").append('<li><a href="#">New list item</a></li>');
11
    });
12
});
13
</script>
14
</head>
15
<body>
16
    <ul id="menu">
17
        <li><a href="#">Home</a></li>
18
        <li><a href="#">About</a></li>
19
        <li><a href="#">Services</a></li>
20
    </ul>
21
    <button type="button">Add New LI Element</button>
22
</body>
23
</html>
 

在微博、微信、公众号、小程序分享此示例。 如果您觉得有帮助,请给我们一个赞。