Recently, jquery has been used, and I have always wanted to write a framework similar to myself. You can click it like jquery.
In jquery, the value of the control is obtained in this way, $ ("# D "). val (), and I want to implement this function here. $ ("ID "). val ();
Code
VaR CZF = {
$: Function (ID ){
This [0] = Document. getelementbyid (ID); // This is the key to get the control object
Return this; // return the CZF object
},
// CZF. ID ('dd'). Val ();
VAL: function (){
Return this [0]. value;
}
};
CZF. _ namespace = true; // In vs 2008, you can add a smart prompt.
VaR CZF ={$: function (ID) {}, VAL: function () {}} is written in JSON,
The key point is this [0] = Document. getelementbyid (ID );
Then return this; when returning the obtained control to the CZF object, you can use CZF. $ ("ID"). Val ();
What I get with CZF. $ ("testid") is actually the CZF object, which has an attribute and two methods.
HTML page
Code
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> CZF implements the $ ("ID"). Val () function similar to jquery </title>
<SCRIPT type = "text/JavaScript" src = "ic. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "CZF. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
/** // * Function testclick (){
VaR testinput = IC. getelementsbyclassname ("testme", "input ");
For (VAR I = 0; I <testinput. length; I ++ ){
Alert (testinput [I]. value );
}
}*/
Function FN (){
Alert (CZF. $ ('testid'). Val ());
}
</SCRIPT>
</Head>
<Body>
<Input type = "text" value = "I am CZF" class = "testme" id = "testid"/>
<Input type = "text" value = "test3" class = "testme" id = "testid2"/>
<Input type = "button" value = "clickme" onclick = "FN ();"/>
</Body>
</Html>
You can expand other functions by yourself.
Share a tips. In vs 2008, add
CZF. _ namespace = true; // In vs 2008, two Slide lines can be displayed intelligently.
CZF. _ namespace = true; // In vs 2008, you can add a smart prompt. Here are two Slide lines __