JavaScript 学习
今天没事又来学习JavaScript
i = 123; //10进制: 123
i = 0x123e1; //16进制: 74721
i = 0123; //8进制: 83
i = 123e1; //1230
var o = {};
o.x = 100;
alert(o["x"]);
我更喜欢把Object当成一个hashtable来使用
对象的直接定义:
var o1 = {x:1, y:2, total:3};
var o2 = {1:1, 2:2, x: "hello"};
数组的直接定义:
var b = [1, true, [1,2], {x:1, y:2}, "Hello"];
怎样把10000写成10,000.00
function NumberToStr(n)
{
var Num = new Number(n);
return Num.toLocaleString();
}
利用自定义函数实现表达式求值
function CalcExpress(exp)
{
var func = new Function("return " + exp + ";");
return func();
}
alert(CalcExpress("1000 * 90 - 2 ^ 2"));
var a = null;
var b = undefined;
alert(a == b); //will show true
alert(a === b); //will show false
navigator.appName //IE will return Microsoft Internet Explorer
navigator.appVersion
var query = location.search.substring(1); //Get the substring of the URL following ?
location.hash = "#top"; //Scroll to a named portion of the document
try
{
throw new SyntaxError("Error: Cannot find file.");
}
catch(e)
{
alert(e.message);
}
i = 123; //10进制: 123
i = 0x123e1; //16进制: 74721
i = 0123; //8进制: 83
i = 123e1; //1230
var o = {};
o.x = 100;
alert(o["x"]);
我更喜欢把Object当成一个hashtable来使用
对象的直接定义:
var o1 = {x:1, y:2, total:3};
var o2 = {1:1, 2:2, x: "hello"};
数组的直接定义:
var b = [1, true, [1,2], {x:1, y:2}, "Hello"];
怎样把10000写成10,000.00
function NumberToStr(n)
{
var Num = new Number(n);
return Num.toLocaleString();
}
利用自定义函数实现表达式求值
function CalcExpress(exp)
{
var func = new Function("return " + exp + ";");
return func();
}
alert(CalcExpress("1000 * 90 - 2 ^ 2"));
var a = null;
var b = undefined;
alert(a == b); //will show true
alert(a === b); //will show false
navigator.appName //IE will return Microsoft Internet Explorer
navigator.appVersion
var query = location.search.substring(1); //Get the substring of the URL following ?
location.hash = "#top"; //Scroll to a named portion of the document
try
{
throw new SyntaxError("Error: Cannot find file.");
}
catch(e)
{
alert(e.message);
}