答:使用jQueryappend()或prepend()方法
您可以使用jQueryappend()或prepend()方法向DOM添加或插入元素。jQueryappend()方法将内容插入到匹配元素的末尾,而prepend()方法将内容插入到匹配元素的开头。
下面的示例将向您展示如何使用jQuery方法轻松地将新项目添加到HTML有序列表的末尾append()。让我们尝试一下,看看它是如何工作的:
例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Add Elements to DOM</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            $("ol").append("<li>list item</li>"); 
        });
    });
</script>
</head>
<body>
    <button>Add new list item</button>
    <ol>
        <li>list item</li>
        <li>list item</li>
        <li>list item</li>
    </ol>
</body> 
</html>
                    	
                    	
                    	  
                    	    
                    	    
                    	    
                    	 
    如果您觉得本文的内容对您的学习有所帮助:
     
                    	
                    	   
                    	   关键字:
jQuery