1. Business requirements: Make a button object and then call it like Winfrom:
First we create a new MyControls js file: (Insert the following code)
//the object-oriented idea used here is to create a new button objectvarbutton =function(ClientId) { This. Control =NULL;//Properties: The button object's own This. ID =NULL;//the ID of the button object This. Value =NULL;//the value displayed by the button object This. Click =NULL;//Click events for Button Objects //Next is the initialization, the properties of all the buttons This. init =function () { This. id = ClientId;//This is the ID that the page passed over. This. Control = $ ("#" + ClientId);//This is the control that is bound by the ID varbutton_html = ' <div href= ' # "id=" Button_ ' + This. id+ ' "class=" button "> ' + This. Value + ' </div> ';//This is the HTML file we want to insert. This. Control.after (button_html); //Binding a point-and- Click event$ ("#button_" + This. id+). Unbind ("click"). Bind ("click", This. click); This. Control.hide ();//hide the current control }; }
What do we do with this object next?
First, we first import the jquery plugin
And then we're going to introduce the path to this file:
Next write the style of the button:
<style type= "Text/css" >. Button{padding:10px 20px 10px 20px;Border:Medium Solid #FF00FF;width:Auto;Height:20px;float: Left;Background-color:#808080;font-family:Young Circle;font-size:Large;Font-weight:Bold; }</style>
Next, we'll write in your Web page:
<DivID= "BTN"></Div>//Here is our to change it into a button<Scripttype= "Text/javascript"> varBtn_button= Newbutton ("btn"); //here is a new button for the object, there is no feeling very like the development of WinfromBtn_button.value= "a button"; //Here's a property assignment for him.Btn_button.click= function () { //Here is the button click eventAlert ("The show has come out ·"); } btn_button.init (); //then initialize the button, note!!! Initialization must be performed only after all property assignments have been completed </Script>
Save, open, and run to see the results.
Custom JS Control-simple example