Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaScriptÖ®±£ÁôСÊýµãºóÖ¸¶¨Î»Êý

ÔÚ¿ª·¢¹ý³ÌÖо­³£Óöµ½Òªµ÷ÕûСÊýµÄ¸ñʽ£¬Èç±£ÁôСÊýµãºóÁ½Î»µÈµÈ¡£·½·¨Ò²ÆÄΪ³£¼û£¬±¸ÍüÈçÏ¡£
 µÚÒ»ÖÖ£¬ÀûÓÃmath.round 
   var original=28.453
1) //round "original" to two decimals
var result=Math.round(original*100)/100;  //returns 28.45
2) // round "original" to 1 decimal
var result=Math.round(original*10)/10;  //returns 28.5
µÚ¶þÖÖ£¬js1.5ÒÔÉÏ¿ÉÒÔÀûÓÃtoFixed(x) £¬¿ÉÖ¸¶¨Êý×Ö½ØÈ¡Ð¡Êýµãºó xλ
3) //round "original" to two decimals
var result=original.toFixed(2); //returns 28.45
4) // round "original" to 1 decimal
var result=original.toFixed(1); //returns 28.5
ÒÔÉÏÁ½ÖÖ·½·¨×îͨÓ㬵«È´ÎÞ·¨Âú×ãÄ³Ð©ÌØÊâÒªÇ󣬱ÈÈç±£ÁôСÊýµãºóÁ½Î»£¬Èç¹û²»ÂúÁ½Î»£¬²»ÂúÁ½Î»Ôò²¹Áã¡£´Ëʱ¾ÍÓÐÁ˵ÚÈýÖÖ·½·¨¡£
µÚÈýÖÖ£¬×ª»»º¯Êý£¬Õâ¶Î´úÂëÀ´Ô´ÓÚ¹úÍâÒ»¸öÂÛ̳¡£
function roundNumber(number,decimals) {
var newString;// The new rounded number
decimals = Number(decimals);
if (decimals < 1) {
newString = (Math.round(number)).toString();
} else {
var numString = number.toString();
if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
numString += ".";// give it one at the end
}
var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
if (d1 != ".") {
cutoff -= 1;
d1 = Number(numString.substring(cutoff,cutoff+1));
} else {
cutoff -= 1;
}
}
}
d1 += 1;
}
if (d1 == 10) {
numString = numString.substring(0, numString.lastIndexOf("."));
var roundedNu


Ïà¹ØÎĵµ£º

Javascript Êý×Ö¶ººÅ·Ö¸ô

½ñÌì¿´µ½Ò»¶ÎÉñµÃÒ»ËúºýÍ¿µÄJavascript´úÂë
(13223342.9269).toFixed(2)=13223342.93;
(13223342.9269).toLocaleString()=13,223,342.93;
formatNum(13223342.9269)=13,223,342.9269;
delFormat(13,223,342.9269)=13223342.9269;
//È¥µô¶ººÅ
function delFormat(str){
  return str.replace(/,/g,"");
&n ......

javascript¼ÓÔØxmlÎļþ

<mce:script language="javascript" type="text/javascript"><!--
//ÐèÒª¶ÁÈ¡µÄxmlÎļþ
var uRl = "jsReadXml.xml";
var xmlDoc;
//³õʼ»¯£¬¸øÉÏÊö¶¨Òå±äÁ¿¸³Öµ
// function showcurcity(){
if(window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM&q ......

JavascriptµÄIEºÍFirefox¼æÈÝÐÔ»ã±à

ÒÔÏÂÒÔ IE ´úÌæ Internet Explorer£¬ÒÔ MF ´úÌæ Mozzila Firefox
1. document.form.item ÎÊÌâ
(1)ÏÖÓÐÎÊÌ⣺
ÏÖÓдúÂëÖдæÔÚÐí¶à document.formName.item("itemName") ÕâÑùµÄÓï¾ä£¬²»ÄÜÔÚ MF ÏÂÔËÐÐ
(2)½â¾ö·½·¨£º
¸ÄÓà document.formName.elements["elementName"]
(3)ÆäËü
²Î¼û 2
2. ¼¯ºÏÀà¶ÔÏóÎÊÌâ
(1)ÏÖÓÐÎÊÌ⣠......

JavaScript Moduleģʽ(ÒëÎÄ)


JavaScript Module Pattern
£¨
JavaScript
Module
ģʽ£© 
À´Ô´£º
1.      
http://yuiblog.com/blog/2007/06/12/module-pattern/
2.      
http://yuiblog.com/blog/2006/06/01/global-domination/
 
È«¾Ö±äÁ¿ÊÇÓкܴóΣº¦µÄ¡£ÔÚ
YU ......

JavaScriptÖеÄJSON

Ô­Ö·£ºhttp://www.dreamdu.com/blog/2008/10/19/json_in_javascript/
JavaScriptÖеÄJSON
×÷ÕߣºDouglas Crockford
Ô­ÎÄÍøÖ·£ºhttp://www.json.org/js.html
ÒëÕߣº¿É°®µÄºï×Ó
JavaScriptÕâÖÖ±à³ÌÓïÑÔÊ×ÒªµÄÄ¿µÄÊÇΪNetscape NavigatorÌṩһÖÖÒ³Ãæ½Å±¾ÓïÑÔ¡£ËüÈÔ±»ÆÕ±éµÄÈÏΪÊÇJavaµÄÒ»¸ö×Ó¼¯£¬µ«ÊÂʵ²¢·ÇÈç´Ë¡£ËüÊ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ