¼òµ¥µÄjavascriptСÊýµãÅжÏ
ÎÒÔÚjavaScript ÓÃÕâ¸ö´úÂëÅжÏÊäÈëµÄÖµÊÇ·ñÊÇÊý×Ö£¬
ÔÊÐíСÊýµãÊäÈëµÄ»°£¬ Ó¦¸Ã¼Óʲô£¿ ÎÒ¼ÓÁË \. ÊÔÁËÊÔ²»ÐУ¬
ÓÐÄÇλÓÐÏֳɵĴúÂ룬 Ìṩ²Î¿¼ÒÔÏ°É
txt = document.getElementById('num').value;
for (i=0; i <txt.length; i++) {
c = txt.charAt(i);
if ("0123456789".indexOf(c,0) < 0) {
alert("ÊäÈëµÄÖµÊÇÊý×ÖÒÔÍâ");
}
}
¹È¸è°Ù¶È¶¼¿ÉÒÔ¡£Êý×ÖÑéÖ¤µÄJSº¯ÊýºÜ¶àµÄ¡£µ«ÊǶ¼ÊÇÓÃÕýÔò×öµÄ¡£»¹Ã»¿´µ½¹ýÄãÕâôдµÄ¡£
ÓÃÕýÔò±í´ïʽ
str.match("\\d*")
À´Åжϰɡ£
txt = document.getElementById('num').value;
for (i=0; i <txt.length; i++) {
c = txt.charAt(i);
if ("0123456789.".indexOf(c,0) < 0) {
alert("ÊäÈëµÄÖµÊÇÊý×ÖÒÔÍâ");
}
}
¼Ó¸öµã¾Í¿ÉÒÔÁË
jsÓиöº¯Êý isNaN(val)¡¡¡¡¡¡Èç¹ûÊÇÊý×ÖÔò·µ»Ø false
ÊÔ¹ý isNaN(val) ÓеãµÄ»°·µ»Øfalse
Â¥Ö÷ÄãÒ»¶¨ÒªÓÃÄãµÄд·¨Ã´£¿ÓÃÕýÔòÓÐɶ²»ºÃ£¿ÄÜʵÏÖ¹¦ÄܾÍÐÐÁËߣ¡ÎªºÎÈç´Ë½ÏÕ棿¿ì˵£¬ÄãÕâ¸ö߹ͷƬ×Ó£¡¹þ¹þ£¡Æäʵ4Â¥µÄд·¨¾ÍÂú×ãÁË°¡£¬»¹ÄÜÑéÖ¤¸ºÊýÄØ¡£3Â¥µÄÒ²¿ÉÒÔ°¡£¡ÄѵÀÄ㻹²»ÂúÒ⣿
/^-{0,1}[0-9]+\.{0,1}[0-9]*$/.test(±äÁ¿)
¶¥7Â¥ºÍ8à¶
4Â¥µÄÊԳɹ¦ÁË¡£¡£
¸Ðл¸÷λ£¡£¡
IceWee ÈÃÄú׿±ÁË£¬ »¹ÊÇллÄã°¡
Ïà¹ØÎÊ´ð£º
ÈçÓÐÒ»¸ötextbox£¬Óû§ÊäÈëºóµãbutton°´Å¥Ê±£¬ÊµÏÖÓÃJavaScript¶ÔtextboxÊäÈëÐÅÏ¢µÄÑéÖ¤£¬ÒªÇóÓÃJavaScriptÀ´ÊµÏÖ£¬±ÈÈçÑéÖ¤Óû§ÊäÈëµÄÊÇ·ñÊÇÊý×Ö¡£
Ï£Íû½«HTML´úÂëÒ»²¢Ð´³öÀ´¹þ£¬Ð»Ð»
HTML code:
<!DOC ......
ÕâÊÇÎÒµÄÎı¾¿ò
<input type="text" size="60" name="password_answer" id="pwdanswer" value="$!password_answer" >
Ìá½»°´Å¥
<input clas ......
ÎÒÏëÉèÖÃbodyÖеÄÊý¾Ý¾àÀëä¯ÀÀÆ÷×ó±ß¿òÒ»¶¨¾àÀëʹÓÃmargin-left¿ÉÒÔÉèÖ㬵«ÊÇÎÒÏ£ÍûÕâ¸öÖµÊǼÆËã³öÀ´µÄ£¬Ò²¾ÍÊÇҪʹÓÃJavaScript¼ÆËãÒ»ÏÂÈ»ºóÔÙʹbodyÏÔʾ½á¹û¡£²»ÖªµÀ¸ÃÔõôÉèÖã¬Ôõôµ÷Óã¬Ï£Íû´ó¼Ò°ïÖúһϣ¬¸ø¸ ......
˵µ½ JavaScript µÄ³õʼ»¯×°ÔØ, ¿ÉÄÜ onload ÊDZ»Á¢¿ÌÏëµ½µÄ·½·¨. µ«ÊÇ onload ²»ÊÇÔÚ document ¼ÓÔØÍê³ÉµÄʱºòµ÷ÓõÄ, ¶øÊÇÔÚÒ³ÃæËùÓÐÔªËØ (°üÀ¨Í¼Æ¬µÈ) È«²¿¼ÓÔØÍê³É²Å»áµ÷ÓÃ. Ò²¾ÍÊÇ˵, Èç¹ûÄãµÄÒ³ÃæÉÏÓиö³ß´çºÜ ......
<script type="text/javascript">
var name = "The Window";
¡¡¡¡ var object = {
¡¡¡¡¡¡¡¡name : "My Object",
¡¡¡¡¡¡¡¡getNameFunc : ......