将原型脚本转换为jquery脚本

时间:2013-03-26 04:43:48

标签: javascript jquery prototypejs

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

我需要将原型转换为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();
    }

1 个答案:

答案 0 :(得分: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()));
    }
}