【问题标题】:how can i change default language and font of html textarea and disable other languages and font?如何更改 html textarea 的默认语言和字体并禁用其他语言和字体?
【发布时间】:2012-08-25 07:57:36
【问题描述】:

我有一个评论框(textarea)。我想首先更改 textarea 的默认语言和默认字体,而客户端无法更改语言或字体。 http://www.haveeru.com.mv/dhivehi/business/126135 转到此链接并单击下面的发表评论按钮。将出现一个文本区域。这正是我希望做的。相同的语言(divehi)相同的字体。我尝试了很多方式。但它在开始时使用英语。谢谢你。

【问题讨论】:

    标签: html css fonts textarea font-face


    【解决方案1】:

    他们使用自己的字体,每次您想查看某人使用的字体/大小/颜色时,请查看 view-source,在本例中为 css

    例如:

    @charset "utf-8";
    @font-face {
        font-family: "MV Waheed";
        src: local("MV Waheed"), url(/dhivehi/fonts/mv_waheed.otf) format("opentype");
    }
    @font-face {
        font-family: "MV Faseyha";
        src: local("MV Faseyha"), url(/dhivehi/fonts/mv_faseyha.otf) format("opentype");
    } 
    

    或 Javascript 扩展

    (function ($) {
        $.fn.thaana = function (options) {
            var settings = {
                keyboard: 'phonetic'
            };
            return this.each(function () {
                if (options) {
                    $.extend(settings, options);
                }
                var keyboards = {
                    'phonetic': {
                        33: '!',
                        34: '"',
                        35: '#',
                        36: '$',
                        37: '%',
                        38: '&',
                        39: '\'',
                        40: ')',
                        41: '(',
                        42: '*',
                        43: '+',
                        44: '،',
                        45: '-',
                        46: '.',
                        47: '/',
                        58: ':',
                        59: '؛',
                        60: '>',
                        61: '=',
                        62: '<',
                        63: '؟',
                        64: '@',
                        65: 'ާ',
                        66: 'ޞ',
                        67: 'ޝ',
                        68: 'ޑ',
                        69: 'ޭ',
                        70: 'ﷲ',
                        71: 'ޣ',
                        72: 'ޙ',
                        73: 'ީ',
                        74: 'ޛ',
                        75: 'ޚ',
                        76: 'ޅ',
                        77: 'ޟ',
                        78: 'ޏ',
                        79: 'ޯ',
                        80: '÷',
                        81: 'ޤ',
                        82: 'ޜ',
                        83: 'ށ',
                        84: 'ޓ',
                        85: 'ޫ',
                        86: 'ޥ',
                        87: 'ޢ',
                        88: 'ޘ',
                        89: 'ޠ',
                        90: 'ޡ',
                        91: ']',
                        92: '\\',
                        93: '[',
                        94: '^',
                        95: '_',
                        96: '`',
                        97: 'ަ',
                        98: 'ބ',
                        99: 'ޗ',
                        100: 'ދ',
                        101: 'ެ',
                        102: 'ފ',
                        103: 'ގ',
                        104: 'ހ',
                        105: 'ި',
                        106: 'ޖ',
                        107: 'ކ',
                        108: 'ލ',
                        109: 'މ',
                        110: 'ނ',
                        111: 'ޮ',
                        112: 'ޕ',
                        113: 'ް',
                        114: 'ރ',
                        115: 'ސ',
                        116: 'ތ',
                        117: 'ު',
                        118: 'ވ',
                        119: 'އ',
                        120: '×',
                        121: 'ޔ',
                        122: 'ޒ',
                        123: '}',
                        124: '|',
                        125: '{',
                        126: '~'
                    },
                    'typewriter': {
                        33: '!',
                        34: '؛',
                        35: '#',
                        36: '$',
                        37: '%',
                        38: '&',
                        39: 'ﷲ',
                        40: ')',
                        41: '(',
                        42: '*',
                        43: '+',
                        44: 'ށ',
                        45: '-',
                        46: 'ޓ',
                        47: 'ޯ',
                        58: 'ޡ',
                        59: 'ފ',
                        60: '\\',
                        61: '=',
                        62: 'ޞ',
                        63: '؟',
                        64: '@',
                        65: '<',
                        66: 'ޟ',
                        67: 'ޏ',
                        68: '.',
                        69: '“',
                        70: '،',
                        71: '"',
                        72: 'ޥ',
                        73: 'ޣ',
                        74: 'ޢ',
                        75: 'ޘ',
                        76: 'ޚ',
                        77: 'ޝ',
                        78: 'ޛ',
                        79: 'ޠ',
                        80: 'ޙ',
                        81: '×',
                        82: '/',
                        83: '>',
                        84: ':',
                        85: 'ޜ',
                        86: 'ޗ',
                        87: '’',
                        88: 'ޕ',
                        89: 'ޤ',
                        90: 'ޖ',
                        91: 'ލ',
                        92: ']',
                        93: '[',
                        94: '^',
                        95: '_',
                        96: '`',
                        97: 'ި',
                        98: 'ޅ',
                        99: 'ސ',
                        100: 'ް',
                        101: 'ާ',
                        102: 'ަ',
                        103: 'ެ',
                        104: 'ވ',
                        105: 'މ',
                        106: 'އ',
                        107: 'ނ',
                        108: 'ކ',
                        109: 'ބ',
                        110: 'ދ',
                        111: 'ތ',
                        112: 'ހ',
                        113: 'ޫ',
                        114: 'ީ',
                        115: 'ު',
                        116: 'ޭ',
                        117: 'ރ',
                        118: 'ޔ',
                        119: 'ޮ',
                        120: 'ޑ',
                        121: 'ގ',
                        122: 'ޒ',
                        123: '÷',
                        124: '}',
                        125: '{',
                        126: '~'
                    }
                };
                $(this).keypress(function (e) {
                    if (e.ctrlKey) {
                        return true;
                    } else if (e.which == 16) {
                        return true;
                    } else {
                        if (keyboards[settings.keyboard][e.which]) {
                            var current, sTop = $(this).scrollTop();
                            if ($(this).get(0).selectionStart || $(this).get(0).selectionStart == 0) {
                                var selected = $(this).get(0).selectionStart + 1;
                                current = $(this).val().substring(0, $(this).get(0).selectionStart) + keyboards[settings.keyboard][e.which] + $(this).val().substring($(this).get(0).selectionEnd, $(this).val().length);
                                $(this).val(current);
                                $(this).get(0).setSelectionRange(selected, selected);
                                $(this).get(0).focus();
                            } else if (document.selection) {
                                var selected = document.selection.createRange();
                                selected.text = keyboards[settings.keyboard][e.which];
                                $(this).focus();
                            } else {
                                current = $(this).val();
                                current += keyboards[settings.keyboard][e.which];
                                $(this).val(current);
                            }
                            $(this).scrollTop(sTop);
                            return false;
                        } else {
                            return true;
                        }
                    }
                });
            });
        };
    })(jQuery);
    
    $(selector).thaana();
    

    JSFiddle

    不是他们可以改变语言,而是如果你改变字体,字体就会产生语言行为。

    看看Google WebFonts

    【讨论】:

    • 我从他们的服务器下载了这些字体并上传到我的,我使用了上面提到的@font-face css,但它仍然无法正常工作。感谢您的帮助:)
    • 他们有字体系列MV WaheedMV Faseyha 你是如何尝试使用它们的?
    • 我从 www.haveeru.com.mv/dhivehi/fonts/mv_waheed.otf 和 www.haveeru.com.mv/dhivehi/fonts/mv_faseyha.otf 下载并使用了同名 MV Waheed 和 MV Faseyha.same 脚本,但我将下载的字体放入我的 htdocs 中,因此路径不同。css 样式表和字体保存在同一个 htdocs 目录中。所以它只是 /mv_waheed.otf 和 /mv_faseyha.otf
    • 我看到了,这些字体似乎有些东西,我不确定它们是否受到限制或类似的东西,但这是解决方案:jsfiddle.net/zNL48
    • 这也是我不明白的一件事。无论如何,非常感谢您的帮助..
    【解决方案2】:

    您提到的网站使用 JavaScript 将表单控件的正常功能替换为完全不同的东西。你需要模仿这个效果。

    【讨论】:

    • 你能告诉我一个可以用来做这个的JS脚本吗。谢谢你的帮助:)
    猜你喜欢
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2013-02-22
    • 2019-09-12
    • 2019-04-21
    • 1970-01-01
    相关资源
    最近更新 更多