LuaÓëjavascriptµÄ²îÒì
LuaÓëjavascriptµÄ²îÒì - [luaѧϰ]
תÔØ
http://huazjxy.blogbus.com/logs/60132016.html
LuaÄ£ÄâÆ÷js·½°¸
1.Óï·¨¼¶Ä£Äâ
luaÓëjsÓïÑÔ²îÒì
1.1×¢ÊÍ
js Ϊ//,luaΪ--.
1.2±äÁ¿
jsÀûÓÃvalÀ´ÉùÃ÷È«¾Ö±äÁ¿²»´æÔÚ¾Ö²¿±äÁ¿£¬luaÔò²»ÐèÒªÖ±½Ó¶¨Î»ÔòΪȫ¾Ö±äÁ¿£¬localÉùÃ÷ÔòΪ¾Ö²¿±äÁ¿¡£
1.3ÔËËã·û
js
+ - * / % ++ --
= += -= *= /= %=
Ö§³Ö×Ö·û´® +
txt1 = "what a very";
txt2 = "nice day";
txt3 =txt1 " " +txt2;
´òÓ¡txt3Êä³ö½á¹ûΪ"what a very nice day".
¹æÔò:
°ÑÊý×ÖÓë×Ö·û´®Ïà¼Ó£¬½á¹û½«³ÉΪ×Ö·û´®.
lua
¶þÔª:+ - * / ^ %
Ò»Ôª:-(¸ººÅ)
lua×Ö·û´®Æ´½ÓΪ..
Èç"Hello ".."World"Æ´½Ó³ÉHello World
1.4¹Øϵ²Ù×÷·û
js¹Øϵ²Ù×÷·û
== ===(È«µÈ) != > < >= <=
lua¹Øϵ²Ù×÷·û
< > <= >= == ~=(²»µÈÓÚ)
1.5 Âß¼ÔËËã·û
js
&& || !
lua
and or not
1.6 If ...ElseÓï¾ä
js Ààc
if else
lua
if then else
if then
elseif then
else
end
Ò»¶¨ÒªÓÐend
1.7 SwitchÓï¾ä
lua²»Ö§³ÖSwitch Óï¾ä
1.8 ÏûÏ¢¿ò
js
¾¯¸æ¿ò alert("Îı¾")
È·ÈÏ¿ò prompt("Îı¾","ĬÈÏÖµ")
lua
À©Õ¹Ö§³Ö¾¯¸æ¿òºÍÈ·ÈÏ¿ò
1.9 º¯Êý
js
function º¯ÊýÃû(²ÎÊý)
{
¡¡¡¡´úÂ룮£®£®
}
js´ø{}Àà c
lua
function º¯ÊýÃû( ²ÎÊý)
end
luaÀàvb ½Å±¾
2.0 For Ñ»·
js:Ààc
for (i=0;i<=10;i++)
{
document.write("The number is " + i)
document.write("<br />")
}
lua:·ÖÁ½ÖÖ Êý×ÖÐÍFor ºÍ·ºÐÍFor
Êý×ÖÐÍFor:
for var= exp1,exp2,exp3 do
<Ö´ÐÐÌå>
end
var´Óexp1±ä»¯µ½exp2£¬stepΪexp3µÝÔö
²»Ö¸¶¨exp3ĬÈÏΪ1
for i =1,100 do
print(i)
end
for i =1,100,2 do
print(i)
end
·ºÐÍFor
·ºÐÍForÑ»·Í¨¹ýÒ»¸öµü´úÆ÷(iterator)º¯ÊýÀ´±éÀúËùÓÐÖµ£º
--´òÓ¡Êý×éa µÄËùÓÐÖµ
for i,v in pairs(a) do print(v) end
Lua»ù´¡¿âÌṩÁËipairs,ÕâÊÇÒ»¸öÓÃÓÚ±éÀúÊý×éµÄµü´úÆ÷º¯Êý¡£
ÔÚÿ´ÎÑ»·ÖÐi»á±»¸³ÓèÒ»¸öË÷ÒýÖµ£¬Í¬Ê±v»á±»¸³ÓèÒ»¸ö¶ÔÓ¦ÓÚ
¸ÃË÷ÒýµÄÊý×éÔªËØÖµ¡£
---´òÓ¡table tÖÐËùÒÔµÄkey
for k in pairs(t) do print(k) end
2.1 WhileÑ»·
js: Ààc
while (±äÁ¿<=½áÊøÖµ)
{
ÐèÖ´ÐеĴúÂë
}
lua:
i =1;
while a[i] do
print(a[i])
i = i+1;
end
ͬʱlua»¹Ö§³Örep
Ïà¹ØÎĵµ£º
Ò³ÃæÆÁ±ÎÁ˻سµ£¬½á¹û¶àÐÐÊäÈëµÄTextbox±¯¾çÁË£¬Ö»ÄÜÓÃjsÖØд»Ø³µÊ¼þ£¬±¸·ÝÒ»ÏÂ
pageloadÀï
txt_eng.Attributes.Add("onkeypress", "enter(this)");
js£º
function enter(obj) {
if (event.keyCode == 13) {
&nb ......
Ò»°ãÎÒ們寫Notes For Web ³Ìʽ時ºÜ長Óõ½URL傳遞һЩ資訊,ÔÚRelease 6 ¶àÖ§Ô®ÁË@UrlQueryStringµÄ¹«Ë¾來Ö±½ÓץȡURL參數,ÕæÊǺÃÓõĹ«Ê½°¢.²»過ʹÓÃ這個當È»還ÊdzÔServerµÄ資Ô´(ЧÄÜ),ÄÜÓà JavaScript ......
ÊÂʵÉÏIEÒѾΪÎÒÃÇÄÚǶÁËWebBrowser¿Ø¼þ£¬ÒѾÄܹ»ºÜºÃµÄÖ§³ÖÎÒÃdz£ÓõĴòÓ¡¹¦ÄÜÁË¡£Í¨¹ý¸Ã¿Ø¼þµÄ¹¦Äܵ÷Óã¬Óû§¿ÉÒÔ½«µ±Ç°µÄHtmlÒ³ÃæÊä³öµ½´òÓ¡»úÉÏ£¬Óû§Ö»ÐèÒª½«Òª´òÓ¡µÄÊý¾Ý×éÖ¯³ÉHtmlÒ³Ã棬Ȼºóµ÷ÓÃWebBrowserµÄ´òÓ¡¹¦ÄܾͿÉÒԺܺõÄʵÏÖËù¼û¼´ËùµÃµÄ´òÓ¡¹¦ÄÜ¡£²»¹ýÕâÖÖ´òÓ¡´æÔÚµÄȱµã¾ÍÊÇ´òÓ¡¾«¶È²»¹»£¬Èç¹ûÐèÒª¾«È· ......
µÚÒ»ÖÖ:
<!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>ÎÞ±êÌâÎ ......
<script>
//дcookiesº¯Êý ×÷ÕߣºµÔÕñ¿
function SetCookie(name,value)//Á½¸ö²ÎÊý£¬Ò»¸öÊÇcookieµÄÃû×Ó£¬Ò»¸öÊÇÖµ
{
var Days = 30; //´Ë cookie ½«±»±£´æ 30 Ìì
var exp = new Date(); //new Date("December 31, 9998");
......