切换jQuery重叠

时间:2015-07-09 23:01:51

标签: jquery html

我正在使用jQuery的按钮脚本(来源:https://jqueryui.com/button/#checkbox)。

当我使用.toggle

时,我遇到了一个问题
  <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Button - Checkboxes</title>
  <link rel="stylesheet"     href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">

  <style>
  #format { margin-top: 2em; }
  </style>
</head>
<body>
<div id="format">
  <input type="checkbox" id="check1"><label for="check1">Option 1</label>
  <input type="checkbox" id="check2"><label for="check2">Option 2</label>
  <input type="checkbox" id="check3"><label for="check3">Option 3</label>
    <p id="text1">1</p>
<p id="text2">2</p>
<p id="text3">3</p>
<p id="text4">4</p>
<p id="text5">5</p>
<p id="text6">6</p>
<p id="text7">7</p>
<p id="text8">8</p>
<p id="text9">9</p>
<p id="text10">10</p>
<p id="text11">11</p>      
<script>
$(function() {
      $( "#check" ).button();
      $( "#format" ).buttonset();
  });
  $( "#check2" ).click(function() {
      $( "#text2, #text3, #text6, #text7, #text8, #text9" ).toggle(display);

  });$( "#check3" ).click(function() {
      $( "#text2, #text3, #text5, #text6, #text7, #text8, #text9, #text10, #text11" ).toggle();
  });
</script>
</div>
</body>
</html>

正如您所看到的,我想切换的一些内容会出现2次。

我希望能够随意检查和取消选中按钮,因此使用.hide代替不起作用,因为它们不会再次出现在第二次点击。

如果两者都被选中,我想要一个出现两次隐藏的字段。

任何人都有解决方案吗?

0 个答案:

没有答案
相关问题