听说wmlscript和javascript差不多,我想知道他是怎么声明的,javascript得写在<script></script>,不知道wmlscript是怎么写的,如果我要写成像javascript那种js脚本,我又应该怎么声明呢,哪位大哥能不能帮我写个最简单的例子,回答得好我会提高分数的!!!多谢了!
问题补充:<go href="validator.wmls#validate()"/>用这个我的会出现下载文件的对话框呀,不知道是怎么回事呀!,能不能再完整点,我用的是opera7模拟器,在wml文件中是不是要把那个wmls文件引用进来呀,就这里不会写呀!
m3gate安装目录下有例子,你可以看看
--------------calc.wmls代码如下------------------
复制内容到剪贴板
代码:
extern function reset()
{
WMLBrowser.setVar("user", "0");
WMLBrowser.setVar("memory", "0");
WMLBrowser.setVar("op", "1"); // +
WMLBrowser.setVar("flush", "true");
WMLBrowser.refresh();
}
//-------------------------------------------------------------------------------
extern function digit(digit)
{
var wmlFlush = WMLBrowser.getVar("flush");
var wmlUser = WMLBrowser.getVar("user");
var fUser = Lang.parseFloat(wmlUser);
if (wmlFlush == "true")
{
wmlUser = "";
WMLBrowser.setVar("flush", "false");
}
if (digit < 10)
{
wmlUser += String.toString(digit);
}
else if (digit == 10) // +/-
{
if (String.length(wmlUser) == 0 || fUser == 0.0)
{
return;
}
if (String.charAt(wmlUser, 0) == "-")
{
wmlUser = String.subString(wmlUser, 1, String.length(wmlUser) - 1);
}
else
{
wmlUser = "-" + wmlUser;
}
}
else if (digit == 11) // .
{
var nPos = String.find(wmlUser, ".");
if (nPos == -1)
{
if (String.length(wmlUser) == 0)
{
wmlUser = "0";
}
wmlUser += ".";
}
}
WMLBrowser.setVar("user", wmlUser);
WMLBrowser.refresh();
}
//-------------------------------------------------------------------------------
extern function operation(op)
{
var wmlUser = WMLBrowser.getVar("user");
var fUser = Lang.parseFloat(wmlUser);
if (fUser == invalid)
{
WMLBrowser.go("index.wml#cError");
return;
}
var wmlMemory = WMLBrowser.getVar("memory");
var fMemory = Lang.parseFloat(wmlMemory);
var wmlOp = WMLBrowser.getVar("op");
var nOp = Lang.parseInt(wmlOp);
if (nOp == 1) // +
{
fMemory += fUser;
}
else if (nOp == 2) // -
{
fMemory -= fUser;
}
else if (nOp == 3) // *
{
fMemory *= fUser;
}
else if (nOp == 4) // /
{
fMemory /= fUser;
}
WMLBrowser.setVar("flush", "true");
fUser = fMemory;
nOp = op;
if (op == 0)
{
nOp = 1;
fMemory = 0.0;
}
WMLBrowser.setVar("user", String.toString(fUser));
WMLBrowser.setVar("memory", String.toString(fMemory));
WMLBrowser.setVar("op", String.toString(nOp));
WMLBrowser.refresh();
}
----------index.wml代码如下----------------------------
复制内容到剪贴板
代码:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<template>
<do type="prev" label="back">
<prev/>
</do>
</template>
<card id="cMain" title="Calculator" onenterforward="calc.wmls#reset()">
<p>
<!-- input name="user" value="0" maxlength="8"/ -->$(user)<br/>
<!-- 789 / C-->
<a href="calc.wmls#digit(7)"><img src="7.wbmp" width="14" height="14" vspace="1" hspace="1" alt="7"/></a>
<a href="calc.wmls#digit(8)"><img src="8.wbmp" width="14" height="14" vspace="1" hspace="1" alt="8"/></a>
<a href="calc.wmls#digit(9)"><img src="9.wbmp" width="14" height="14" vspace="1" hspace="1" alt="9"/></a>
<a href="calc.wmls#operation(4)"><img src="div.wbmp" width="14" height="14" vspace="1" hspace="1" alt="/"/></a>
<a href="calc.wmls#reset()"><img src="clear.wbmp" width="14" height="14" vspace="1" hspace="1" alt="C"/></a>
<br/>
<!-- 456 * -->
<a href="calc.wmls#digit(4)"><img src="4.wbmp" width="14" height="14" vspace="1" hspace="1" alt="4"/></a>
<a href="calc.wmls#digit(5)"><img src="5.wbmp" width="14" height="14" vspace="1" hspace="1" alt="5"/></a>
<a href="calc.wmls#digit(6)"><img src="6.wbmp" width="14" height="14" vspace="1" hspace="1" alt="6"/></a>
<a href="calc.wmls#operation(3)"><img src="mul.wbmp" width="14" height="14" vspace="1" hspace="1" alt="*"/></a>
<br/>
<!-- 123 - -->
<a href="calc.wmls#digit(1)"><img src="1.wbmp" width="14" height="14" vspace="1" hspace="1" alt="1"/></a>
<a href="calc.wmls#digit(2)"><img src="2.wbmp" width="14" height="14" vspace="1" hspace="1" alt="2"/></a>
<a href="calc.wmls#digit(3)"><img src="3.wbmp" width="14" height="14" vspace="1" hspace="1" alt="3"/></a>
<a href="calc.wmls#operation(2)"><img src="minus.wbmp" width="14" height="14" vspace="1" hspace="1" alt="-"/></a>
<br/>
<!-- 0 +/- . + = -->
<a href="calc.wmls#digit(0)"><img src="0.wbmp" width="14" height="14" vspace="1" hspace="1" alt="0"/></a>
<a href="calc.wmls#digit(10)"><img src="sign.wbmp" width="14" height="14" vspace="1" hspace="1" alt="+/-"/></a>
<a href="calc.wmls#digit(11)"><img src="point.wbmp" width="14" height="14" vspace="1" hspace="1" alt="."/></a>
<a href="calc.wmls#operation(1)"><img src="plus.wbmp" width="14" height="14" vspace="1" hspace="1" alt="+"/></a>
<a href="calc.wmls#operation(0)"><img src="eq.wbmp" width="14" height="14" vspace="1" hspace="1" alt="="/></a>
</p>
</card>
<!-- An invalid number was entered -->
<card id="cError" title="Error">
<p>
Invalid number.
</p>
</card>
</wml>
再给你一个学习的网站
http://www.w3school.com.cn/wmlscript/index.asp
比如:wmlscript 定义在 *.wmls文件中。
然后在xml文件中调用是这样的
<go href="validator.wmls#validate()"/>
WMLScript教程
http://www.wapease.com/html/tip5/index.html
无线标记语言(WML)基础之WMLScript基础
http://dev.yesky.com/491/2115991.shtml