<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml><HTMLxmlns= "http://www.w3.org/1999/xhtml"> <Head> <title>jquery Gets the value of a text box</title> <Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" /> <Scriptsrc= "Jquery-1.5.1.min.js"type= "Text/javascript"></Script> <Scripttype= "Text/javascript"> //use ID to get$ (document). Ready (function(){ //1 $("#button_text1"). Click (function(){ varRESULT1= $("#input_text1"). Val (); Alert ("RESULT1 =" +RESULT1); }); //2 $("#button_text2"). Click (function(){ varresult2= $("input[id= ' input_text2 ']"). Val (); Alert ("result2 =" +result2); }); //3 $("#button_text3"). Click (function(){ varRESULT3= $("input[id= ' input_text3 ']"). attr ("value"); Alert ("RESULT3 =" +RESULT3); }); //4. The value in input can be obtained by the value of type (not shown) /*$ ("#button_text4"). Click (function () {var result4 = $ ("input[type= ' text ']"). Val (); Alert ("RESULT4 =" + RESULT4); }); */ //5. The value in input can be obtained by the value of name (not shown) /*$ ("#button_text5"). Click (function () {var result5 = $ ("input[name= ' text ']"). Val (); Alert ("RESULT5 =" + RESULT5); }); */ }); </Script> </Head> <Body> <!--gets the value of the text box: Way One - <DivID= "Test1"> <inputID= "Input_text1"type= "text"value= "Test1"style= "width:100px;" /> <ButtonID= "Button_text1">Test1</Button> </Div> <!--get the value of the text box: mode two - <DivID= "Test2"> <inputID= "Input_text2"type= "text"value= "Test2"style= "width:100px;" /> <ButtonID= "Button_text2">Test2</Button> </Div> <!--gets the value of the text box: Way three - <DivID= "Test3"> <inputID= "Input_text3"type= "text"value= "Test3"style= "width:100px;" /> <ButtonID= "Button_text3">Test3</Button> </Div> </Body></HTML>
jquery gets the various ways in which the values in input type= "text"