(function($) {    $.alerts = {        // These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time        verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels  垂直偏移从
        horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/横向偏移从
        repositionOnResize: true,           // re-centers the dialog on window resize重新中心的窗口对话框中调整
        overlayOpacity: .40,                // transparency level of overlay透明度的覆盖
        overlayColor: '#FFF',               // base color of overlay基色的覆盖
        draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)使对话框可拖动
        okButton: ' 确定 ',         // text for the OK button文本确定按钮
        cancelButton: ' Cancel ', // text for the Cancel button案文取消按钮
        dialogClass: null,                  // if specified, this class will be applied to all dialogs 如果指定,这个类        // Public methods        alert: function(message, title, callback) {
            if (title == null) title = 'Alert';
            $.alerts._show(title, message, null, 'alert', function(result) {
                if (callback) callback(result);
            });
        },        confirm: function(message, title, callback) {
            if (title == null) title = 'Confirm';
            $.alerts._show(title, message, null, 'confirm', function(result) {
                if (callback) callback(result);
            });
        },        prompt: function(message, value, title, callback) {
            if (title == null) title = 'Prompt';
            $.alerts._show(title, message, value, 'prompt', function(result) {
                if (callback) callback(result);
            });
        },        // Private methods        _show: function(title, msg, value, type, callback) {            $.alerts._hide();
            $.alerts._overlay('show');            $("BODY").append(
  '<div id="popup_container">' +
    '<h1 id="popup_title"></h1>' +
    '<div id="popup_content">' +
      '<div id="popup_message"></div>' +
'</div>' +
  '</div>');            if ($.alerts.dialogClass) $("#popup_container").addClass($.alerts.dialogClass);            // IE6 Fix
            var pos = ($.browser.msie && parseInt($.browser.version) <= 6) ? 'absolute' : 'fixed';            $("#popup_container").css({
                position: pos,
                zIndex: 99999,
                padding: 0,
                margin: 0
            });            $("#popup_title").text(title);
            $("#popup_content").addClass(type);
            //$("#popup_content").ClassName = type;
            $("#popup_message").text(msg);
            $("#popup_message").html($("#popup_message").text().replace(/\n/g, '<br />'));            $("#popup_container").css({
                minWidth: $("#popup_container").outerWidth(),
                maxWidth: $("#popup_container").outerWidth()
            });            $.alerts._reposition();
            $.alerts._maintainPosition(true);
            alert(escape($.alerts.okButton));
这是一个Jquery Alert 插件里面的代码,我修改了些东西,却发现有些小问题。。请看红色字体,为什么定义OK Cancel的时候没问题。而为中文“确定”“取消”的时候就是乱码,显示不了,我也试了escape和unescape都没有用希望有牛人解释

解决方案 »

  1.   

    (function($) {    $.alerts = {        // These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time        verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels  垂直偏移从
            horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/横向偏移从
            repositionOnResize: true,           // re-centers the dialog on window resize重新中心的窗口对话框中调整
            overlayOpacity: .40,                // transparency level of overlay透明度的覆盖
            overlayColor: '#FFF',               // base color of overlay基色的覆盖
            draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)使对话框可拖动
            okButton: '&nbsp;确定&nbsp;',         // text for the OK button文本确定按钮
            cancelButton: '&nbsp;Cancel&nbsp;', // text for the Cancel button案文取消按钮
            dialogClass: null,                  // if specified, this class will be applied to all dialogs 如果指定,这个类        // Public methods        alert: function(message, title, callback) {
                if (title == null) title = 'Alert';
                $.alerts._show(title, message, null, 'alert', function(result) {
                    if (callback) callback(result);
                });
            },        confirm: function(message, title, callback) {
                if (title == null) title = 'Confirm';
                $.alerts._show(title, message, null, 'confirm', function(result) {
                    if (callback) callback(result);
                });
            },        prompt: function(message, value, title, callback) {
                if (title == null) title = 'Prompt';
                $.alerts._show(title, message, value, 'prompt', function(result) {
                    if (callback) callback(result);
                });
            },        // Private methods        _show: function(title, msg, value, type, callback) {            $.alerts._hide();
                $.alerts._overlay('show');            $("BODY").append(
      '<div id="popup_container">' +
        '<h1 id="popup_title"></h1>' +
        '<div id="popup_content">' +
          '<div id="popup_message"></div>' +
    '</div>' +
      '</div>');            if ($.alerts.dialogClass) $("#popup_container").addClass($.alerts.dialogClass);            // IE6 Fix
                var pos = ($.browser.msie && parseInt($.browser.version) <= 6) ? 'absolute' : 'fixed';            $("#popup_container").css({
                    position: pos,
                    zIndex: 99999,
                    padding: 0,
                    margin: 0
                });            $("#popup_title").text(title);
                $("#popup_content").addClass(type);
                //$("#popup_content").ClassName = type;
                $("#popup_message").text(msg);
                $("#popup_message").html($("#popup_message").text().replace(/\n/g, '<br />'));            $("#popup_container").css({
                    minWidth: $("#popup_container").outerWidth(),
                    maxWidth: $("#popup_container").outerWidth()
                });            $.alerts._reposition();
                $.alerts._maintainPosition(true);
                alert(escape($.alerts.okButton));
    这是一个Jquery Alert 插件里面的代码,我修改了些东西,却发现有些小问题。。请看红色字体,为什么定义OK Cancel的时候没问题。而为中文“确定”“取消”的时候就是乱码,显示不了,我也试了escape和unescape都没有用希望有牛人解释
      

  2.   

    。。怎么没有红色字体
    okButton: '&nbsp;确定&nbsp;',         // text for the OK button文本确定按钮
            cancelButton: '&nbsp;Cancel&nbsp;', // text for the Cancel 
     $.alerts._reposition();
                $.alerts._maintainPosition(true);
                alert(escape($.alerts.okButton));
      

  3.   

    把【确定】替换为 &#30830;&#23450;
    把【取消】替换为 &#21462;&#28040;
    试试看!
      

  4.   

    我也遇到过同样的问题,我的解决方法是在引用这个js 时加上<script src="..."  charset="gb2312"></script>
      

  5.   

    html编码,简单的方法,直接保存js文件为utf-8编码格式
      

  6.   

    简单的方法,直接保存js文件为utf-8编码格式----------
    怎么保存为这个格式。。?
      

  7.   

    呵呵,那就结贴给分哈只是把 escape 的结果再次转为实体编码,这样在页面中就能直接显示了,
    例如:【确】的 escape 编码为 %u786E,而 786E 的十进制就是 30830,再加上 &# 就可以了!这招只在国外网站上学来的,他们在显示中文时就这做!
      

  8.   

    另存时选择编码格式,许多文本编辑器都支持,例如 Editplus。
      

  9.   

    使用记事本打开,另存为-编码类型-选择utf-8 确定
      

  10.   

    使用这个函数即ok//HTML编码(10.16)
    function HTMLbm(code){
        var _s="";
    for(var i=0;i<code.length;i++){
            _s+="&#"+code.charCodeAt(i);
    }
    return _s;
    }var str=HTMLbm("hello,你好");
    document.write(str);
    alert(str);
      

  11.   

    我也碰到这个问题了,用记事本另存为UTF-8字符编码格式的就可以了!
      

  12.   

    =>&#119&#111&#114&#100
      

  13.   

    >&#119&#111&#114&#100