JavaScript Tutorial/Dojo toolkit/ToggleButton

Материал из Web эксперт
Перейти к: навигация, поиск

Add toggle button to tool bar

<html>
  <head>
    <link rel="StyleSheet" type="text/css"
      href="js/dojo/dijit/themes/tundra/tundra.css">
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/",
        parseOnLoad : true
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
    <script>
      dojo.require("dojo.parser");
      dojo.require("dijit.form.Button");
      dojo.require("dijit.Toolbar");
    </script>
  </head>
  <body class="tundra">
      <div dojoType="dijit.Toolbar">
        <div dojoType="dijit.form.Button" iconClass="dijitEditorIcon dijitEditorIconCut" showLabel="true">Cut</div>
        <div dojoType="dijit.form.Button" iconClass="dijitEditorIcon dijitEditorIconCopy" showLabel="true">Copy</div>
        <div dojoType="dijit.form.Button" iconClass="dijitEditorIcon dijitEditorIconPaste" showLabel="false">Paste</div>
        <span dojoType="dijit.ToolbarSeparator"></span>
        <div dojoType="dijit.form.ToggleButton" iconClass="dijitEditorIcon dijitEditorIconBold" showLabel="false">Bold</div>
      </div>
  </body>
</html>


Toggle button on change event

<html>
  <head>
    <link rel="StyleSheet" type="text/css" href="js/dojo/dijit/themes/tundra/tundra.css">
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/",
        parseOnLoad : true
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
    <script>
            dojo.require("dijit.form.ToggleButton");
    </script>
  </head>
  <body class="tundra">
    <button dojoType="dijit.form.ToggleButton">asdf
     <script type="dojo/method" event="onChange" args="newValue">
       alert(newValue);
     </script>
    </button>
     
</body>
</html>


Use toggle button and tool bar, add icon to toggle button

<html>
  <head>
    <link rel="StyleSheet" type="text/css"
      href="js/dojo/dijit/themes/tundra/tundra.css">
    <script type="text/javascript">
      var djConfig = {
        baseScriptUri : "js/dojo/",
        parseOnLoad : true
      };
    </script>
    <script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
    <script>
      dojo.require("dojo.parser");
      dojo.require("dijit.form.Button");
      dojo.require("dijit.Toolbar");
    </script>
  </head>
  <body class="tundra">
     <div id="toolbar1" dojoType="dijit.Toolbar"
          style="width:25px;">
       <div dojoType="dijit.form.ToggleButton"
            iconClass="dijitEditorIcon dijitEditorIconBold"
            showLabel="false">
       </div>
     </div>
  </body>
</html>