[note] JS 全形轉半形

include jquery

$(document).ready(function(){
$('#submit').click(function(){
value = $('#enname').val();
result = "";
for(i=0; i<=value.length; i++){
    if(value.charCodeAt(i)== 12288){
      result += " ";
    }else{
      if(value.charCodeAt(i) > 65280 && value.charCodeAt(i) < 65375){
        result += String.fromCharCode(value.charCodeAt(i) - 65248);
      }else{
        result += String.fromCharCode(value.charCodeAt(i));
      }
    }
  }
  $('#enname').val(result)
});
});

張貼留言

0 留言