0

底部代码将文本输入中的数字转换为波斯语数字和镜像。

我需要将原型转换为 jquery,请帮助我

 String.prototype.toFaDigit = function() {
        return this.replace(/\d+/g, function(digit) {
            var ret = '';
            for (var i = 0, len = digit.length; i < len; i++) {
                ret += String.fromCharCode(digit.charCodeAt(i) + 1728);
            }

            return ret;
        });
    };

    String.prototype.toEnDigit = function() {
    return this.replace(/[\u06F0-\u06F9]+/g, function(digit) {
        var ret = '';
        for (var i = 0, len = digit.length; i < len; i++) {
            ret += String.fromCharCode(digit.charCodeAt(i) - 1728);
        }

        return ret;
    });
};
 function ChekNumLang_ChekBox(MainTextFieldName) {
    var fieldObj = document.getElementById(MainTextFieldName);
    if (document.getElementById("FarsiNum").checked) {
        fieldObj.value = fieldObj.value.toFaDigit();
    }
    else {
        fieldObj.value = fieldObj.value.toEnDigit();
    }
4

1 回答 1

0

如果由我决定,我会做类似的事情

StringUtils = {};

StringUtils.toFaDigit = function(string) {
    return string.replace(/\d+/g, function(digit) {
                var ret = '';
                for (var i = 0, len = digit.length; i < len; i++) {
                    ret += String.fromCharCode(digit.charCodeAt(i) + 1728);
                }

                return ret;
            });
};

StringUtils.toEnDigit = function(string) {
    return string.replace(/[\u06F0-\u06F9]+/g, function(digit) {
                var ret = '';
                for (var i = 0, len = digit.length; i < len; i++) {
                    ret += String.fromCharCode(digit.charCodeAt(i) - 1728);
                }

                return ret;
            });
};

function ChekNumLang_ChekBox(MainTextFieldName) {
    var fieldObj = $('#' + MainTextFieldName)
    if ($('#FarsiNum').is(':checked')) {
        fieldObj.val(StringUtils.toFaDigit(fieldObj.val()));
    } else {
        fieldObj.val(StringUtils.toEnDigit(fieldObj.val()));
    }
}
于 2013-03-26T04:50:28.793 回答