Blogger Information
Blog 35
fans 0
comment 1
visits 42598
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
prepend(),appendTo(),insertbefore();insertafter();的使用方法
魏先生的博客
Original
745 people have browsed it

实例

<!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()在元素的外面的后面加

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post