function ord(string) {
var str = string + '',
code = str.charCodeAt(0);
if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
var hi = code;
if (str.length === 1) {
return code; // This is just a high surrogate with no following low surrogate, so we return its value;
// we could also throw an error as it is not a complete character, but someone may want to know }
var low = str.charCodeAt(1);
return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
}
if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate return code; // This is just a low surrogate with no preceding high surrogate, so we return its value;
// we could also throw an error as it is not a complete character, but someone may want to know
}
return code;
}
}
$(document).ready(function() {
var maxTxtNumber = 8;
var arrTxtNumber = new Array();
var txtvalues = new Array();
var arr = {};
$('.numericonly').keypress(function (e) {
var t = $(this).val();
var k = e.which;
delete arr[8];
if ((e.which >= 49 && e.which <= 55) || e.which == 8) {
if (e.which == 8) {
var s = new String(t);
s = s.charCodeAt(0);
delete arr[s];
}
if (arr[k]) {
e.preventDefault();
} else {
arr[k] = e.which;
}
} else {
e.preventDefault();
}
});
});
該代碼適用於Firefox,但不適用於IE和Chrome?Javascript不能在IE和Chrome上工作(它可以在Firefox上運行)
先生/女士您的回答會有很大的幫助。謝謝++
當你說「不工作」時,你的意思是什麼:根本不工作或不按預期工作(然後你必須解釋什麼)。 – Nivas 2012-08-06 00:45:50
http://jsfiddle.net/ABCPY/採用縮進格式。 a)這個腳本的目的是什麼?b)你是否知道你的整個ord函數只返回str.charCodeAt(0)或null? – Doug 2012-08-06 00:59:19
你似乎沒有調用'ord()'。爲什麼代碼是相關的? – jfriend00 2012-08-06 01:48:34