ÕÅТÏêjavascript½²×ù±Ê¼ÇËÄ
Ò»£¬È«¾Ö±äÁ¿ºÍ¾Ö²¿±äÁ¿µÄ±È½Ï
<script type="text/javascript">
<!--
var msg = 'È«¾Ö±äÁ¿';
function show()
{
msg = '¾Ö²¿±äÁ¿'; //ÐÞ¸ÄÈ«¾Ö±äÁ¿µÄÖµ
}
show();
alert(msg); //´ËʱµÄֵΪ‘¾Ö²¿±äÁ¿’
//-->
</script> <script type="text/javascript">
<!--
var msg = 'È«¾Ö±äÁ¿';
function show()
{
var msg;
msg = '¾Ö²¿±äÁ¿'; //Ö»Ð޸ľֲ¿±äÁ¿µÄÖµ
}
show();
alert(msg); //´ËʱµÄֵΪ‘¾Ö²¿±äÁ¿’
//-->
</script>
¶þ£¬javascriptÖвÎÊý¸öÊý¿É±äµÄº¯Êý
ÔÚº¯ÊýÄÚ²¿Ê¹ÓÃarguments¶ÔÏóÀ´·ÃÎʵ÷ÓóÌÐò´«µÝµÄËùÓвÎÊý£¬¶øÔÚº¯ÊýµÄÉùÃ÷Öк¯Êý²ÎÊýÁбíΪ¿Õ¼´¿É
eg:
<script type="text/javascript">
<!--
function textparams()
{
var params = '';
//ÔÚº¯ÊýÄÚ²¿Ê¹ÓÃarguments¶ÔÏóÀ´·ÃÎʵ÷ÓóÌÐò´«µÝµÄËùÓвÎÊý
for(var i=0;i<arguments.length;i++)
{
params = params + '' + arguments[i];
}
textparams('abc',123);
textparams(123,456,'abc');
}
// -->
</script>
Èý£¬´´½¨¶¯Ì¬º¯Êý£¨ÔÚc/c++ÖÐÀûÓú¯ÊýÖ¸ÕëÀ´ÊµÏÖ£©
var varName = new Function(argument1,...,lastargument);
˵Ã÷£º
ËùÓеIJÎÊý¶¼±ØÐëÊÇ×Ö·û´®ÀàÐ͵ģ¬×îºóµÄÒ»¸ö²ÎÊý±ØÐëÊÇÕâ¸ö¶¯Ì¬º¯ÊýµÄ¹¦ÄܳÌÐò´úÂë¡£
eg:
<script type="text/javascript">
<!--
var square = new Function('x','y','var sum,sum=x*x+y*y;return sum;');
alert(square(2,3));
// -->
</script>
¶¯Ì¬º¯ÊýÓÐʲôÓã¿
¿ÉÒÔÔÚ³ÌÐòÖ´Ðйý³ÌÖУ¬¶¯Ì¬±ä»»º¯ÊýµÄº¯Êý´úÂ룻
ËÄ£¬javascriptµÄϵͳº¯Êý(¿ÉÒÔÖ±½Óµ÷ÓÃ)
1£¬encodeURI·½·¨
·µ»Ø¶ÔÒ»¸öURI×Ö·û´®±àÂëÖеĽá¹û£¬±¾ÖÊÊÇUTF-8±àÂë
eg:
var urlStr = encodeURI('http://fanli.qq.com/index.html?a=ddd&msg=Öйú');
alert(urlStr);
2, decodeURI·½·¨
¶ÔURI±àÂë½øÐнâÂë³Â×î³õʼµÄ×Ö·û´®²¢·µ»Ø
3£¬parseInt·½·¨
½«Ò»¸ö×Ö·û´®°´Ö¸¶¨µÄ½øÖÆת»»³ÉÒ»¸öÕûÊý
parseInt(numString, [rad
Ïà¹ØÎĵµ£º
ÔÚJavaScriptÖд´½¨Ð¶ÔÏó
£¨ÀîÏþ»ª¡¡2001Äê04ÔÂ29ÈÕ 01:50£©
¡¡¡¡Ê¹ÓÃJavaScript¿ÉÒÔ´´½¨×Ô¼ºµÄ¶ÔÏó¡£ËäÈ»JavaScriptÄÚ²¿ºÍä¯ÀÀÆ÷±¾ÉíµÄ¹¦ÄÜÒÑÊ®·ÖÇ¿´ó£¬µ«JavaScript»¹ÊÇÌṩÁË´´½¨Ò»¸öжÔÏóµÄ·½·¨¡£Ê¹Æä²»±ØÏñ³¬Îı¾±êʶÓïÑÔÄÇÑù£¬ÇóÓÚ»òÆäËü¶àýÌ幤¾ß£¬¾ÍÄÜÍê³ÉÐí¶à¸´ÔӵŤ×÷¡£
¡¡¡¡ÔÚJavaScriptÖд´½¨Ò»¸öÐÂµÄ¶Ô ......
ÉùÃ÷£º
function person(name, country)
{
this.name = name;
this.country = country;
}
ʵÀý»¯¶ÔÏó£º
var theauthor = new person('Daniel', 'U.S.A.');
ÒýÓãº
function sayHello(objPerson)
{
return "Hello " + objPerson. ......
һ˵µ½javascript¾ÍÓÐÈË»áÏëµ½java£¬µ«ÊÇËûÃÇÍê»áÊÇÁ½»ØÊ£¬javascriptÊÇÃæÏò¶ÔÏóµÄ¶¯Ì¬ÀàÐ͵ÄÇø·Ö´óСдµÄ¿Í»§¶Ë½Å±¾ÓïÑÔ£¬Çë×¢Òâ´óСÓÐÇø±ð£¬ÃæÏò¶ÔÏó¡£javascriptÓÃ;ºÜ¶àµÄ£¬Ä¿Ç°¼¸ºõËùÓÐÖ÷Á÷ä¯ÀÀÆ÷¶¼Ö§³Ö¡£µ«ÊÇËûÓÐÒ»¸ö»µ´¦¾ÍÊDZäÁ¿£¬Èçvar
i=4;Õâ¸öi¾ÍÊÇintÀàÐ͵ģ¬var
s="hello",Õâ¸ösÊÇ×Ö·û´®ÀàÐ͵ģ ......
javascriptº¯ÊýµÄ¶¨Òå
1£ºµ÷Óùؼü×ÖfunctionÀ´¹¹Ô죬È磺
function distance(x1,x2,y1,y2)
{
var dx=x2-x1;
var dy=y2-y1;
return Math ......