<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery-3.4.1.min.js"></script>
</head>
<body>
<h1 name="test"></h1>
<h1></h1>
<button>点我</button>
</body>
<script>
$(document).ready(function(){
$('h1[name="test"]').text('你好');
$('button').click(function(event) {
$('h1').text('我是h1');
$('h1[name="test"]').text('我是一个特别的h1');
/* Act on the event */
});
});
</script>
</html>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery-3.4.1.min.js"></script>
</head>
<style type="text/css">
h1:hover{
color:red;
}
</style>
<body>
<h1>我是h1</h1>
<h1>我是h1</h1>
</body>
<script>
$(document).ready(function(){
$('h1').hover(function() {
/* Stuff to do when the mouse enters the element */
$(this).text('进来了');
}, function() {
/* Stuff to do when the mouse leaves the element */
$(this).text('走了');
});
});
</script>
</html>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery-3.4.1.min.js"></script>
</head>
<style type="text/css">
h1:hover{
color:red;
}
</style>
<body>
<h1></h1>
<input type="text">
</body>
<script>
$(document).ready(function(){
$('input').keyup(function(event) {
/* Act on the event */
var content = $(this).val();
$('h1').text(content);
});
});
</script>
</html>
网友评论