我有两个单选按钮来切换两个替代文本,它可以工作:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
type="text/javascript"></script>
<style type="text/css">
.displayNone { display: none; }
</style>
</head>
<body>
<input type="radio" name="toggle" />A
<input type="radio" name="toggle" />B
<span class="A">A</span>
<span class="B displayNone">B</span>
<script type="text/javascript">
$('input[name=toggle]').change(function() {
$('.A, .B').toggleClass('displayNone');
})
</script>
</body>
</html>
现在我想让它成为三个单选按钮来在三个文本之间切换:
<input type="radio" name="toggle" />A
<input type="radio" name="toggle" />B
<input type="radio" name="toggle" />C
<span class="A">A</span>
<span class="B displayNone">B</span>
<span class="C displayNone">C</span>
我正在考虑的解决方案看起来太冗长了。什么是干净的?