引用 | 編輯
ericleesky
2005-03-14 16:33 |
樓主
▼ |
||||||||||||
x0
有興趣的網友,可下載此帖的附件參考參考 做法:將原始碼加入網頁的語法中即可。 步驟一:將以下原始碼加入<HEAD>與</HEAD>標籤之間. <!-- Begin function isvowel(v) { if ((v == "a") || (v == "e") || (v == "i") || (v == "o") || (v == "u")) { return true; } else { return false; }} function toJapanese(inp) { name1 = inp; otp = ""; cnt = 0; k = ""; l = ""; inp = inp.toLowerCase(); while (cnt <= inp.length - 1) { k = inp.charAt(cnt); if ((cnt + 1) > (inp.length - 1)) { l = "u"; } else { l = inp.charAt(cnt+1); } if ((k == " ") || (k == "-") || (k == "'")) { otp = otp + k; cnt += 1; } if ((l == "y") && (!isvowel(k))) { l = "i"; } if (k == "x") { if (cnt == 0) { k = "z"; } else { k = "k"; }} if (k == "g") { if ((l == "e") || (l == "i") || (l == "y")) { k = "j"; } else { if (isvowel(l)) { otp = otp + k + l; cnt += 2; } else { otp = otp + k + "u"; cnt += 1; }}} if (k == "j") { if ((l == "a") || (l == "u") || (l == "o")) { otp = otp + k + l; cnt +=2; } if ((l == "e") || (l == "i")) { otp = otp + "ji"; cnt += 2; }} if (k == "y") { if ((l == "a") || (l == "u") || (l == "o")) { otp = otp + k + l; cnt += 2; } else { k = "i"; }} if (k == "m") { if (isvowel(l)) { otp = otp + k + l; cnt += 2; } else { if ((l == "b") || (l == "m") || (l == "p")) { otp = otp + "n"; cnt += 1; } else { otp = otp + "mu"; cnt += 1; }}} if (isvowel(k) || ((k == "n") && (!isvowel(l)))) { otp = otp + k; cnt = cnt + 1; } if (k == "q") { k = "k"; } if (k == "v") { k = "b"; } if (k == "l") { k = "r";} if (k == "c") { if (l == "h") { otp = otp + "chi"; cnt += 3; } else { if ((l == "e") || (l == "i") || (l == "y")) { k = "s"; } else { k = "k"; }}} if (k == "w") { if ((l == "a") || (l == "o")) { otp = otp + k + l; cnt += 2; } else { if ((l == "i") || (l=="e")) { otp = otp + "u" + l; cnt += 2; } else { k = "b"; }}} if ((k == "b") || (k == "k") || (k == "r")) { if (isvowel(l)) { otp = otp + k + l; cnt += 2; } else { otp = otp + k + "u"; cnt += 1; }} if (k == "d") { if ((l == "i") || (l == "a") || (l == "e")) { otp = otp + "de"; cnt += 2; } if ((l == "u") || (l == "o")) { otp = otp + "do"; cnt += 2; } if (!isvowel(l)) { otp = otp + "de"; cnt += 1; }} if (k == "f") { otp = otp + "fu"; cnt += 1; if (isvowel(l)) { cnt += 1; }} if (k == "h") { if (l == "u") { otp = otp + "fu"; cnt += 2; } else { if (isvowel(l)) { otp = otp + k + l; cnt += 2; } else { otp = otp + "fu"; cnt += 1; }}} if (k == "z") { if (l == "i") { k = "j"; } else { if (isvowel(l)) { otp = otp + k + l; cnt += 2; } else { otp = otp + "zu"; cnt += 1; }}} if (k == "n") { if (isvowel(l)) { otp = otp + k + l; cnt += 2; }} if (k == "p") { if (l == "h") { otp = otp + "fu"; cnt += 2; } if (isvowel(l)) { otp = otp + k + l; cnt += 2; } else { otp = otp + "pu"; cnt += 1; }} if (k == "s") { if ((l == "i") || (l == "h")) { otp = otp + "shi"; cnt += 2; if (l == "h") { cnt += 1; }} else { if (isvowel(l)) { otp = otp + k + l; cnt += 2; } else { otp = otp + "su"; cnt += 1; }}} if (k == "t") { if ((l == "a") || (l == "e") || (l == "o")) { otp = otp + k + l; cnt += 2; } if ((l == "u") || ((!isvowel(l)) && (!(l == "h")))) { otp = otp + "tsu"; cnt += 1; if (l == "u") { cnt += 1; } if ((l == "s") && (inp.charAt(cnt + 1) == "u")) { cnt += 2; }} if (l == "i") { otp = otp + "chi"; cnt += 2; } if (l == "h") { otp = otp + "fu"; cnt += 3; }}} name2 = "" + otp.charAt(0).toUpperCase(); for (j = 1; j <= otp.length - 1; j++) { name2 += otp.charAt(j); } alert(name1 + " 日文發音是: \"" + name2 + "\""); } // End --> </script> ‧步驟二:將以下原始碼加入網頁中欲出現轉換器的地方即可. <form> 輸入您的名字英文拼音: <input type=text name="personname" size=15><BR><BR> <input type=button value="日文發音顯示" onfiltered="toJapanese(this.form.personname.value);"> </form>
x0
|
引用 | 編輯
PeterPan
2005-03-15 20:54 |
1樓
▲ ▼ |
TO 樓主:
這是JavaScript,不是Java歐,貼在「HTML & JavaScript & Flash」比較合適 最前面少了一行:<script language="javascript"> 我照著您說的方法作,卻沒有出現alert視窗告訴我答案,所以語法也有錯誤的地方,建議您到 這邊 確認看看哪邊出錯 x0 |
引用 | 編輯
ericleesky
2005-03-15 21:50 |
2樓
▲ |
下面是引用PeterPan於2005-03-15 20:54發表的 : 嗯嗯~~~謝謝你的注意~因為我這些資料我也是以前從郵件那備份過來的!!~ 只是想提供給有興趣的人玩玩~其實我也沒每個的去RUN過~在此向大家致歉~ x0 |