Javascriptº¯ÊýÀàÐÍÅжÏÍêÃÀ½â¾ö·½°¸
Javascriptº¯ÊýÀàÐÍÅжÏÍêÃÀ½â¾ö·½°¸
ÔÚÅжϺ¯ÊýÀàÐÍʱ£¬ÎÒÃÇͨ³£Ê¹ÓÃtypeof·½·¨£¬Ò»°ãÇé¿öÏ£¬Ëü»áµÃµ½ÎÒÃÇËùÔ¤ÏëµÄЧ¹û¡£µ«ÊÇ£¬ÓÐһЩϸ½Ú²¢²»ÎªÎÒÃÇËùÊìÖª¡£John Resig ÔÚ·ÖÎöÁËÕâЩϸ½ÚÖ®ºó£¬ÎªÎÒÃÇÌṩÁËÒ»¸öÍêÃÀµÄ½â¾ö·½°¸£¬±¾ÎĽ«×÷Ïêϸ½éÉÜ£º
Ò»¡¢´«Í³·½·¨²»ÎªÈËËùÖªµÄϸ½Ú
ºÁÎÞÒÉÎÊ£¬ÔÚÅжϺ¯ÊýÀàÐÍʱ£¬ÎÒÃÇʹÓõÄÊÇtypeof·½·¨£¬±ÈÈ磺
function fn(){
//content
}
alert(typeof fn)//½á¹ûÊÇ"function"¡£
µ«ÊÇ£¬¸Ã·½·¨ÔÚһЩä¯ÀÀÆ÷Öв¢²»ÊÇÏñÎÒÃÇÏëÏñµÄÄÇÑù¹¤×÷¡£
1¡¢Firefox2ºÍFirefox3
ÔÚÕâÁ½¸öä¯ÀÀÆ÷ÖУ¬ÓÃtypeof¼ì²âHTML¶ÔÏóÔªËصÄÀàÐÍ£¬µÃµ½ÊÇÒ»¸ö²»¾«È·µÄ“function”½á¹û£¬¶ø²»ÊÇ“object”£¬ÈçHTMLDocument¡£È磺
alert(typeof HTMLDocument);
//ÔÚFirefox2Öнá¹ûÊÇ"function";
//ÔÚFirefox3Öнá¹ûÊÇ"object";
2¡¢Firefox2
¶ÔÓÚÕýÔò±í´ïʽ£¬ÔÚ¸Ãä¯ÀÀÆ÷Öзµ»ØµÄ½á¹ûÊÇ“function”(ÔÚFirefox3Öнá¹ûÊÇ“object”)£¬È磺
var reg = /test/;
alert(typeof reg);
//ÔÚFirefox2Öнá¹ûÊÇ"function";
//ÔÚFirefox3Öнá¹ûÊÇ"object";
×¢£º±¾ÈËÔÚsafariÖвâÊÔ£¬Æä½á¹ûÒ²ÊÇ“function”¡£
3¡¢IE6ºÍIE7
ÔÚIEÖжÔDOMÔªËØʹÓÃtypeof·½·¨£¬µÃµ½µÄ½á¹ûÊÇ“object”¡£È磺
alert(typeof document.getElementsByTagName("body")[0].getAttribute);
//½á¹ûÊÇ"object"
4¡¢Safari 3
safariÈÏΪDOMÔªËصÄNodeListÊÇÒ»¸öº¯Êý£¬È磺
alert(typeof document.body.childNodes);
//½á¹ûÊÇ"function"
ºÜÃ÷ÏÔ£¬Èç¹ûÄãÒª²âÊÔÒ»¸ö¶ÔÏóÊÇ·ñΪº¯Êý£¬Ê¹ÓÃtypeof·½·¨²¢²»ÄÜ´ÓÕæÕýÒâÒåÉϱ£Ö¤²âÊÔ½á¹û¡£ÄÇô£¬ÎÒÃǾÍÐèÒªÒ»ÖÖÔÚËùÓÐä¯ÀÀÆ÷Öж¼Äܱ£Ö¤²âÊÔ
½á¹ûµÄ½â¾ö·½°¸¡£ÎÒÃÇÖªµÀfunction±¾ÉíÓÐapply()ºÍcall()Á½ÖÖ·½·¨£¬µ«ÕâÁ½¸ö·½·¨ÔÚIEÖдæÔÚÎÊÌâµÄº¯ÊýÖв¢²»´æÔÚ£¬ÊÔÊÔÏÂÃæµÄ²â
ÊÔ£º
alert(typeof document.getElementsByTagName("body")[0].getAttribute.call)
//ÔÚIEÖнá¹ûÊÇ"undefined"
ÏÔÈ»£¬ÎÒÃDz»ÄÜÀûÓÃÕâÁ½¸ö·½·¨¡£
¶þ¡¢ÍêÃÀ½â¾ö·½°¸¼°ÊµÏÖ¹ý³Ì
John ResigΪÎÒÃÇÌṩÁËÒ»¸öÍêÃÀµÄ½â¾ö·½°¸£¬Õâ¸ö¸´ÔÓµ«ºÜÎȶ¨µÄÅжÏÒ»¸ö¶ÔÏóÊÇ·ñΪº¯ÊýµÄ·½·¨ÈçÏ£º
function isFunction( fn ) {
return !!fn && !fn.nodeName && fn.constructo
Ïà¹ØÎĵµ£º
<mce:script type="text/javascript"><!--
function SetCookie(name,value,expire) {
var exp = new Date();
exp.setTime(exp.getTime() + expire);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
} ......
Link:http://topic.csdn.net/u/20100317/15/687e21bc-40f3-4f0e-bc22-5f2a32ceb1a3.html?seed=1664090183&r=63989333#r_63989333
<HTML>
<head>
<title>sample</title>
<mce:script language="JavaScript"><!--
var c="FFFFFF";
window.onload=function (){
setInterval(s ......
JavaScript¼üÅÌʼþÕìÌý
ÔÚʹÓÃJavaScript×öWEB¼üÅÌʼþÕìÌý²¶»ñʱ£¬Ö÷Òª²ÉÓÃonkeypress¡¢onkeydown¡¢onkeyupÈý¸öʼþ½øÐгöÀ´¡£¸ÃÈý¸öʼþµÄÖ´ÐÐ˳ÐòÈçÏ£ºonkeydown -> onkeypress ->onkeyup¡£ÔÚÒ»°ãÇé¿öÏ£¬²ÉÓÃÈýÖÖ¼üÅÌʼþ¾ù¿É¶Ô¼üÅÌÊäÈë½øÐÐÓÐЧµÄÏìÓ¦¡£µ±ÔÚʵ¼ÊʹÓÃÖУ¬»á·¢ÏÖÕ⼸ÕßÓÐЩ²»Í¬µÄ²î±ð¡£
......
±¾ÎÄת×Ô£ºhttp://www.w3school.com.cn/js/jsref_tofixed.asp
¶¨ÒåºÍÓ÷¨
toFixed() ·½·¨¿É°Ñ Number ËÄÉáÎåÈëΪָ¶¨Ð¡ÊýλÊýµÄÊý×Ö¡£
Óï·¨
NumberObject.toFixed(num)
²ÎÊýnumÃèÊö±ØÐè¡£¹æ¶¨Ð¡ÊýµÄλÊý£¬ÊÇ 0 ~ 20 Ö®¼äµÄÖµ£¬°üÀ¨ 0 ºÍ 20£¬ÓÐЩʵÏÖ¿ÉÒÔÖ§³Ö¸ü´óµÄÊýÖµ·¶Î§¡£Èç¹ûÊ¡ÂÔÁ˸òÎÊý£¬½«Óà 0 ´úÌæ¡£
......
1
¡¢Àí½âdocument.all
[]
¡¡¡¡´ÓIE4¿ªÊ¼IEµÄobject
model²ÅÔö¼ÓÁËdocument.all
[],À´¿´¿´document.all
[]µÄDescription:
Array
of all HTML tags in the document.Collection of all elements contained by the
object.
¡¡¡¡Ò²¾ÍÊÇ˵document.all
[]ÊÇÎĵµÖÐËùÓбêÇ©×é³ÉµÄÒ»¸öÊý×é±äÁ¿£¬°üÀ¨ÁËÎĵµ¶ÔÏóÖÐËùÓ ......