The grammar rules are as follows:
1. Each line of the program ends with a semicolon
2, notes: "//" or "/ * * /"
3. Use the keyword "var" to declare the variable
how about it? From the above we can see that the WMLScript language and JavaScript language are similar, and WMLScript variable types are: Boolean, Interger, Floating-Point, process control language of String, Invalid WMLScript, the same, as follows:
// if-elseif (x == y) {
X = x * 3.25;} else {x = 0;}
// for loopfor (var counter = 1; counter <500; counter ) {var i = counter * 1.05; somefunction (i);}; // while loopwhile (i> j) {i-;}; / / BREAK
For (var counter = 1; counter <500; counter ) {var i = counter * 1.05; if (counter == 250) Break; SomeFunction (i);}; // continuefor (var counter = -100; counter <100; counter ) {if (counter == 0) Continue; var x = 350 / counter;}; function: WMLScript function usage: Extern function ideterlist block; extern is to make a function There is another file. As follows: Function runtime (distance, speed) {var time = distance / speted; return time;}; this instance is sent into DISTANCE and SPEED two parameters, and then returns the value of Time. If you call the WMLScript built-in function, you must add the class name to which this function belongs, such as calling the length () function of the String class, using: var a = string.length; built-in function . WMLScript has six large built-in functions: LANG: Contains data form, absolute value, random number, etc. Float: floating point number. String: String Length (Length), Charat) and other strings. URL: GetReferer, gethost. WMLBROWSER: Go, Prev, Next, refresh browsing processing. Dialogs: Plug the PROMPT, CONFIRM, ALERT, etc.
First we build a WML file first, Wmlscriptexample.Wml, the content is as follows: XML Version = "1.0"?> Enter stu_id: p> card> you entered: STU_ID: $ (stuid) p> card> wml> Let the user enter the school number, GO's HREF Connect to another .Wmls file, call the checkid function. A WMLScriptexample.wmls file is then established, and the content is as follows: Extern function checkid (struid) {if (string.length (stuid)! = 8) {WMLBROWSER.SETVAR ("stuid", "Error: String Must be 8 Digits Long." WmlBrowser.go ("Wmlscriptexample.wml # results");}; this WMLScript is to check if the STUID string length is 8, and return the result. WmlBrowser.SetVar () Sets the value of the variable, WmlBrowser.go () is positioned to the next WML file, which is the resultS card of Wmlscriptexample.wml. how about it? Is WMLScript very similar to JavaScript? It's just an exact same, it is more functions that match the WML file. Finally, it is necessary to point out that most of the WAP phones (NOKIA7110, Ericsson R320S, etc.) are using UTF-8 encoding, which is to encode unitecode, so if we use Chinese directly in WML / WMLScript, Will be garbled, mobile phone users cannot identify, so we have to make Uniecode's encoding before outputting Chinese. This job will be completed by the server. For example, we use ASP to do this, you can call this function. Implementation of transformation, other languages Implementation Method Similar to: Function C2U (MyText) FOR i = 1 to Len (MyText) 'Treats C = MID (MyText, I, 1) C2U = C2U & "& # x "& HEX (ASCW (C)) &"; "converts the backned Unicode to the sixteen-entered value Nextend function implementation is as follows: (Chinese.asp) <% response.contentType =" text / vnd.wap .wml; charset = UTF-8 "