- //發送表單數據時,取代特殊字元
- function check_data( o ){
- for (var i=0;i < o.elements.length;i++ )
- with ( o.elements[i] ) {
- switch( type ){
- case 'text' :value = value.replace(//'/g,"’").replace(//"/g,"”").replace(//*/g,"*").replace(//|/g,"│").replace(//</g,"<").replace(//>/g,">");break;
- case 'textarea' :value = value.replace(//'/g,"’").replace(//"/g,"”").replace(//;/g,";").replace(//*/g,"*").replace(//|/g,"│").replace(//</g,"<").replace(//>/g,">").replace(//./g,"?");break;
- }
- }
- }
調用:<form id="form1" ……onSubmit="check_data(this);">
或: check_data(document.form1);
document.form1.submit();