Dig into the enumeration functionality in JavaScript

  • 2020-03-30 02:15:01
  • OfStack

Since Microsoft AJAX Library extends JavaScript significantly,

Enumeration, of course, has been added,

This time we'll explore JavaScript's enumeration capabilities.

Because the example is so simple,

So just look at the HTML tag


<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
    <script language="javascript" type="text/javascript"> 
        Type.registerNamespace("BaoBeiMe"); 
        //Register an enumeration
        BaoBeiMe.EnumDepartment = function() { 
        } 
        BaoBeiMe.EnumDepartment.prototype = { 
            One: " Ministry of information ", 
            Two: " Sales department ", 
            Three: " Finance dept. ", 
            Four: " Research and development department " 
        } 
        BaoBeiMe.EnumDepartment.registerEnum("BaoBeiMe.EnumDepartment"); 
        function Button1_onclick() { 
            var enumDepartment = new BaoBeiMe.EnumDepartment(); 
            var lblMsg = $get('<%=lblMsg.ClientID %>'); 
            lblMsg.innerText = "One  is  " + enumDepartment.One + "  ,       " + 
                               "Two  is  " + enumDepartment.Two + "  ,       " + 
                               "Three  is  " + enumDepartment.Three + "  ,       " + 
                               "Four  is  " + enumDepartment.Four + "       "; 
        } 
    </script> 
    <div> 
        <input id="Button1" type="button" value=" Gets all the enumerated values " 
               onclick="return Button1_onclick()" /><br /> 
        <br /> 
        <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label> 
    </div> 
    </form> 
</body> 
</html>

The results of

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201403/20140306091721.png ">


Related articles: