Ms7 Search
Google 搜尋 翻譯
calendar
« 九月 2024 »
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
近期文章
文章分類
網站連結
Syndicate

« | »

javascritp 訊息替換

2012-02-09 @ 19:54 in PHP, JavaScript, Sql

在一個網頁程序中用 javascript 判斷輸入資料內容,在 Dreamweaver 內用 行為的 Onclick 檢驗表單,錯誤訊息會用欄位名稱顯示,為了更明確的讓用戶知道錯誤訊息,就將欄位名稱用中文訊息顯示,用 javascript 的 replace 和 json 寫法如下:

下面黑色字部分是 Dreamweaver 產生的,藍色部分是將錯誤訊息直接用中文顯示,紅色部分是我加入的,這樣就會用中文顯示,檔名前後加 - 是因為避免有部份相同欄位名稱一樣,被替換

<script type="text/javascript">
<!--
function MM_validateForm() { //v4.0
var fname_arr={'-_name-':'姓名','-_year-':'出生年','-_month-':'出生月','-_day-':'出生日','-_epasswd-':'修改列印密碼','-_reg_zip-':'戶籍地址郵遞區號','-_reg_addr-':'戶籍地址','-_school_name-':'國中學校','-_school_no-':'學校代碼','-_sup_name-':'監護人姓名','-_sup_rela-':'監護人關系','-_sup_tel2-':'監護人電話','-_cnt_zip-':'通訊處郵遞區號','-_cnt_addr-':'通訊處地址'};
if (document.getElementById){
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- -'+nm+'- 必須是 e-mail 地址.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- -'+nm+'- 必須是數字.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- -'+nm+'- 必須是數字在 '+min+' 至 '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- -'+nm+'- 不能空白.\n'; }
} 
for(var key in fname_arr){
errors = errors.replace( key , fname_arr[key]) ;
}
if (errors) alert('發生以下錯誤:\n'+errors);
document.MM_returnValue = (errors == '');
} }
//-->
</script>

 

迴響

javascritp 訊息替換 | 豬窩

Nice post. I learn something totally new and challenging
on websites I stumbleupon every day. It will always be interesting to
read through content from other authors and use
something from their websites.

作者 then g @ 01:01, 2020-06-22

javascritp 訊息替換 | 豬窩

Cbd oil that works 2020
Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I acquire in fact loved account your weblog posts.

Anyway I'll be subscribing for your feeds or even I success you get entry to persistently rapidly.
best cbd oil for pain http://tinyurl.com/cbd-oil-that-works-2020 cbd oil
that works 2020 http://tinyurl.com/cbd-oil-that-works-2020

作者 http://tinyurl.com/cbd-oil-that-works-2020 @ 21:46, 2020-06-24

javascritp 訊息替換 | 豬窩

Nice respond in return of this matter with firm
arguments and telling the whole thing regarding that.

作者 web hosting service @ 23:49, 2020-08-08

javascritp 訊息替換 | 豬窩

Hello, I check your blog daily. Your humoristic style is awesome, keep doing
what you're doing!

作者 webhosting @ 18:37, 2020-08-11
«上一篇   1 2 3 4
發表迴響
 authimage