jquery点击当前对象,并alert文本内容
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("This is button: "+$(this).text().trim().substring(7,8));
});
});
</script>
</head>
<body>
<center>
<p>要求按“Button 1”显示 “This is button: 1 ”,以此类推</p>
<button id="btn1">Button 1</button>
<button id="btn2">Button 2</button>
<button id="btn3">Button 3</button>
<hr>
<button id="btn4">Button 4</button>
<button id="btn5">Button 5</button>
<button id="btn6">Button 6</button>
</center>
</body>
</html>