<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>LIST</title>
		<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
		<style type="text/css">
			.box{
				margin: 0 auto;
			}
			.baozi{
				border: solid 1px #C3D6F3;
				text-align: center;
			}
			input{
				background-color: #C3D6F3;
				border: solid 1px #fff;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<input type="submit" value="大象" />
			<input type="submit" value="狮子" />
			<input type="submit" value="老虎" />
			<input type="submit" value="狼狗" />
			<div class="baozi">
				<p>豹子</p>
			</div>
		</div>
		
		<script>
			$(document).ready(function(){
				$('.box').css({'width':'220px','height':'auto','background-color':'#0074e8'});
				
				$(':input:first').click(function(){
					var y = "<p>大象<p>";
					$(y).prependTo($('.baozi'));
					$(this).attr('disabled','disabled');
				})
				
				$(':input').eq(1).click(function(){
					var y = "<p>狮子<p>";
					$(y).appendTo($('.baozi'));
					$(this).attr('disabled','disabled');
				})
				
				$(':input').eq(2).click(function(){
					var y = "<p style='text-align: center;color: blue;'>老虎</p>";
					$(y).insertBefore($('.baozi'));
					$(this).attr('disabled','disabled');
				})
				
				$(':input').eq(3).click(function(){
					var tt = "<p style='text-align: center;color: blue;'>狼狗</p>";
					$(tt).insertAfter($('.baozi'));
					$(this).attr('disabled','disabled');
				})
				
			})
			
		</script>
	</body>
</html>点击 "运行实例" 按钮查看在线实例
prependTo();在元素的前面加
appendTo();在元素的后面加
insertbefore()在元素的外面的前面加
insertafter()在元素的外面的后面加
 
                 
                        
                    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号