返回對象的字符串表示。
objectname.toString([radix])
objectname
必選項。要得到字符串表示的對象。
radix
可選項。指定將數字值轉換為字符串時的進制。
toString 方法是所有內建的 JScript 對象的成員。它的操作依靠于對象的類型:
function functionname( ) { [native code] }Number返回數字的文字表示。String返回 String 對象的值。默認返回 “[object objectname]”,其中 objectname 是對象類型的名稱。下面的例子演示了使用帶有 radix 參數的 toString 方法。上面所示函數的返回值是一個 Radix 轉換表。
function CreateRadixTable (){ var s, s1, s2, s3, x; //聲明變量。s = "Hex Dec Bin /n"; //創建表頭。for (x = 0; x < 16; x++) //根據所示值的{ //數字建立switch(x) //表尺寸。{ //設置欄目間空間。case 0 :s1 = " ";s2 = " ";s3 = " ";break;case 1 :s1 = " ";s2 = " ";s3 = " ";break;case 2 :s3 = " ";break;case 3 :s3 = " ";break;case 4 :s3 = " ";break;case 5 :s3 = " ";break;case 6 :s3 = " ";break;case 7 :s3 = " ";break;case 8 :s3 = "" ;break;case 9 :s3 = "";break;default:s1 = " ";s2 = "";s3 = " ";} //轉換為十六進制、十進制、二進制。s += " " + x.toString(16) + s1 + x.toString(10)s += s2 + s3 + x.toString(2)+ "/n";}return(s); //返回整個radix表。}
新聞熱點
疑難解答