$(":text[number]").live("keyup",function(){ //先把非数字的都替换掉,除了数字和.\d表示数字 \.表示点 而正则中的.表示出了回车和换行以外的字符.在这里正则将非数字和点的字符转为空 this.value = this.value.replace(/[^\d\.]/g,""); //必须保证第一个为数字而不是.将 this.value = this.value.replace(/^\./g,""); //去除所有的汉字 this.value = this.value.replace(/[^\x00-\xff]*/g,""); //保证.只出现一次,而不能出现两次以上 this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); });