知识点:js中的return 不能使js程序停止或者跳出执行,会继续往下执行。要想让js程序停止或者跳出 可以用 return false 就可以了。
代码:
<!---------------------------------------------html---------------------------------------------------------------------------------->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>html3</title>
<meta name="description" content="">
<meta name="author" content="Administrator">
<style type="text/css">
.btn {
background-color: #337ab7;
}
.masthead {
background-color: darken(#428bca, 6.5%);
}
</style>
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<script type="text/javascript" src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>
<script type="text/javascript">
$(function() {
$("#btn2").click(function() {
var v = $(this).text().trim();
if (‘Middle‘ == v) {
$(this).text(‘des‘).siblings().addClass(‘disabled‘);
} else {
$(this).text(‘Middle‘).siblings().removeClass(‘disabled‘);
}
});
$(‘#btn1‘).click(function() {
var v = $(‘#btn2‘).text().trim();
if (‘des‘ == v)
return false;
alert(111);
});
$(‘#btn3‘).click(function() {
var v = $(‘#btn2‘).text().trim();
if (‘des‘ == v)
return false;
alert(222);
});
});
</script>
</head>
<body>
<div>
<header>
<h1>html3</h1>
</header>
<div class="btn-group" role="group">
<button type="button" id="btn1" class="btn btn-default masthead">
Left
</button>
<button type="button" id="btn2" class="btn btn-default">
Middle
</button>
<button type="button" id="btn3" class="btn btn-default">
Right
</button>
</div>
</div>
</body>
</html>
<!---------------------------------------------html---------------------------------------------------------------------------------->
原文:http://www.cnblogs.com/developer-os/p/7020460.html