JavaScript Tutorial/Dojo toolkit/Button

Материал из Web эксперт
Версия от 08:24, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Declare dijit.form.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");
    </script>
  </head>
  <body class="tundra">
        <button dojoType="dijit.form.Button"
          iconClass="dijitEditorIcon dijitEditorIconRedo"
          onClick="alert("Clicked!");">
          Click me
        </button>
  </body>
</html>


Disable, enable 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("dijit.form.Button");
            dojo.require("dijit.form.CheckBox");
    </script>
  </head>
  <body class="tundra">
    <div name="confirmation" dojoType="dijit.form.CheckBox">
        <script type="dojo/method" event="onClick" args="evt">
          if (this.checked)
            dijit.byId("signup").setAttribute("disabled", false);
          else
            dijit.byId("signup").setAttribute("disabled", true);
        </script>
    </div>Text.<br>
    <button id="signup" disabled dojoType="dijit.form.Button" type="submit">Button</button>
     
</body>
</html>


dojo button label

<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.addOnLoad(bn);
      
      function bn() {
        var myDijit = new dijit.form.Button({
          label : "Label",
          onClick : function() { alert("Clicked"); }
        });
        dojo.byId("my").appendChild(myDijit.domNode);
      }
    </script>
  </head>
  <body class="tundra">
     <div id="my">&nbsp;</div>
  </body>
</html>


Show label off

<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");
      dojo.addOnLoad(show);
      
      
      function show() {
        var myDijit = new dijit.Toolbar({ style : "width:26px;" });
        myDijit.addChild(new dijit.form.ToggleButton({
          iconClass : "dijitEditorIcon dijitEditorIconUnderLine",
          showLabel : false
        }));
        dojo.byId("my").appendChild(myDijit.domNode);
      }
    </script>
  </head>
  <body class="tundra">
     <div id="my">&nbsp;</div>
  </body>
</html>


Use predefined icons for buttons

<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>