jquery实例–文档处理–内部插入
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>jQuery实例--文档处理--内部插入</h1>
<ul>
<li>苹果</li>
<li>李子</li>
<li>火龙果</li>
</ul>
名称: <input type="text" name="tname"><br><br>
<button>前插入</button><br><br>
<button>后插入</button><br><br>
</body>
<script src="./jquery-3.5.0.min.js"></script>
<script>
$(function(){
$('button').click(function(){
var tname = $('input[name = "tname"]').val();
switch($(this).html()){
case "前插入":
$('<li>'+tname+'</li>').prependTo('ul');
break;
case "后插入":
$('<li>'+tname+'</li>').appendTo('ul')
break;
}
});
});
</script>
</html>
jquery实例–文档处理–insert
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>jQuery实例</h1>
<ul class="uu">
<li class="active">苹果</li>
<li>香蕉</li>
<li>西瓜</li>
<li>樱桃</li>
<li>白梨</li>
</ul>
名称:<input type="text" name="tname"><br><br>
<button>前添加</button><br><br>
<button>后追加</button>
</body>
<script src="./jquery-3.5.0.min.js"></script>
<script>
$(function(){
$('ul.uu li').click(function(){
$('ul.uu li').removeClass('active');
$(this).addClass('active');
});
$('button').click(function(){
var tname = $('input[name = "tname"]').val();
switch($(this).html()){
case "前添加":
$('<li>'+tname+'</li>').insertBefore('li.active');
break;
case "后追加":
$('<li>'+tname+'</li>').insertAfter('li.active').click(function(){
$('ul.uu li').removeClass('active');
$(this).addClass('active');
});
break;
}
});
});
</script>
</html>
jquery实例–文档处理–外部插入和删除
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1 id="hid">jQuery实例--文档处理--外部插入和删除</h1>
<form >
姓名:<input type="text" title="姓名" name="uname"><br><br>
年龄:<input type="text" title="年龄" name="age"><br><br>
电话:<input type="text" title="电话" name="phone"><br><br>
邮箱:<input type="text" title="邮箱" name="email"><br><br>
地址:<input type="text" title="地址" name="address"><br><br>
</form>
<script src="./jquery-3.5.0.min.js"></script>
<script>
$(function(){
$('input:text').focus(function(){
var title = $(this).prop('title');
$('<span>请输入正确的'+title+'信息</span>').insertAfter(this).css('color','red');
}).blur(function(){
$(this).next('span').remove();
});
});
</script>
</body>
</html>
jquery实例–文档处理–删除操作
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
ul li{margin: 0px; padding: 0px;}
ul{list-style: none;}
ul li{line-height: 40px;padding-left: 20px;margin: 5px;background-color: #ddd;}
ul li:hover{background-color: orange;}
ul li.active{background-color: pink;}
</style>
</head>
<body>
<h1>jQuery实例--文档处理--删除操作</h1>
<ul>
<li>苹果</li>
<li>香蕉</li>
<li>西瓜</li>
<li>芒果</li>
</ul>
<br><br>
<button>删除</button><br><br>
<button>清空</button>
</body>
<script src="./jquery-3.5.0.min.js"></script>
<script>
$(function(){
$('ul li').click(function(){
$(this).toggleClass('active');
});
$('button').click(function(){
switch($(this).html()){
case '删除':
$('ul li.active').remove();
break;
case '清空':
$('ul').empty();
break;
}
});
});
</script>
</html>
jquery实例–显示,隐藏,切换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>jquery--实例</h1>
<button>显示</button>
<button>隐藏</button>
<button>切换</button><br><br>
<img src="./11.jpg" width="300px">
<script src="./jquery-3.5.0.min.js"></script>
<script>
$(function(){
$('button').click(function(){
switch($(this).html()){
case "显示":
$('img').fadeIn('slow');
break;
case "隐藏":
$('img').fadeOut('slow');
break;
case "切换":
$('img').fadeToggle('slow');
break;
}
});
});
</script>
</body>
</html>
jquery实例–效果展示–短信墙特效
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
ul,li{margin: 0px;padding: 0px;}
ul{width: 400px;list-style: none;}
ul li{line-height: 80px;margin-bottom: 2px;background-color: #ddd;}
#did{width: 400px;height: 326px;border: 1px solid orange;overflow: hidden; }
</style>
</head>
<body>
<h1>jQuery实例--jQuery效果展示--短信墙特效</h1>
<div id="did">
<ul class="uu">
<li>苹果</li>
<li>白梨</li>
<li>香蕉</li>
<li>芒果</li>
<li>西瓜</li>
<li>葡萄</li>
</ul>
</div>
</body>
<script src="./jquery-3.5.0.min.js"></script>
<script>
$(function(){
setInterval(function(){
$('ul.uu li:first').slideUp('slow',function(){
$(this).appendTo('ul.uu').show();
});
},3000);
});
</script>
</html>
jquery实例–效果展示–树形菜单
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
ul{display: none;}
h4{line-height: 40px;}
h4:hover{background-color: #ddd;}
</style>
</head>
<body>
<h1>jQuery实例--jQuery效果展示--树形菜单</h1>
<h4>水果菜单列表</h4>
<ul>
<li>苹果</li>
<li>西瓜</li>
<li>李子</li>
</ul>
<h4>水果菜单列表</h4>
<ul>
<li>苹果</li>
<li>西瓜</li>
<li>李子</li>
</ul>
<h4>水果菜单列表</h4>
<ul>
<li>苹果</li>
<li>西瓜</li>
<li>李子</li>
</ul>
<script src="./jquery-3.5.0.min.js"></script>
<script>
$('h4').click(function(){
$(this).next('ul').slideToggle('slow');
});
</script>
</body>
</html>