Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 日志消息的文本框HTML/JS_Javascript_Jquery_Html_Node.js - Fatal编程技术网

Javascript 日志消息的文本框HTML/JS

Javascript 日志消息的文本框HTML/JS,javascript,jquery,html,node.js,Javascript,Jquery,Html,Node.js,在创建自己的解决方案之前,我试图找到一些已经适合我需要的东西。我有一个node.js服务器,可以连接多个客户端/应用程序。这些客户端将向服务器发送日志消息,我希望在面板中显示这些消息 现在,对于日志消息的典型多行文本框,我需要一些功能: /** * Add a message to the gamelog * @param {Object} options : allows custom output * @param {String} options.message : the mess

在创建自己的解决方案之前,我试图找到一些已经适合我需要的东西。我有一个node.js服务器,可以连接多个客户端/应用程序。这些客户端将向服务器发送日志消息,我希望在面板中显示这些消息

现在,对于日志消息的典型多行文本框,我需要一些功能:

/**
 * Add a message to the gamelog
 * @param {Object} options : allows custom output
 * @param {String} options.message : the message to display
 * @param {Boolean} options.isTimed : does the message has a timestamp in front of it?
 * @param {Boolean} options.isError : is the message an error?
 * @param {Boolean} options.isNewline : start the message on a new line
 */
addMessage: function (options) {
    var instance = ns.instance,
        audio = instance.audio,
        audiofx = audio.settings.fx,
        history = this.areaMessage.html();

    // isTimed?
    options.message = options.isTimed
        ? history + this.fieldClock.val() + ': ' + options.message
        : history + options.message;

    // isNewline?
    if (options.isNewline) {
        options.message = options.message + '<br />';
    }

    // message
    this.areaMessage.html(options.message);
    this.scrollTop(this.areaMessage);

    // isError?
    if (options.isError) {
        audio.play(audiofx.error);
    }
},
  • 我需要能够附加日志消息,因为它们将通过WebSocket定期发送
  • 它应该自动向下滚动,除非用户选择文本或向上滚动
  • 它应该能够使用颜色和粗体/常规
我的问题:

上面的用例已经有解决方案了吗?

我可以给你我的解决方案吗?它以前是一个
textarea
,但我已经将它重构为
div
,代码几乎没有变化

代码的一些要点,可在

用于发送日志消息的自定义函数:

/**
 * Add a message to the gamelog
 * @param {Object} options : allows custom output
 * @param {String} options.message : the message to display
 * @param {Boolean} options.isTimed : does the message has a timestamp in front of it?
 * @param {Boolean} options.isError : is the message an error?
 * @param {Boolean} options.isNewline : start the message on a new line
 */
addMessage: function (options) {
    var instance = ns.instance,
        audio = instance.audio,
        audiofx = audio.settings.fx,
        history = this.areaMessage.html();

    // isTimed?
    options.message = options.isTimed
        ? history + this.fieldClock.val() + ': ' + options.message
        : history + options.message;

    // isNewline?
    if (options.isNewline) {
        options.message = options.message + '<br />';
    }

    // message
    this.areaMessage.html(options.message);
    this.scrollTop(this.areaMessage);

    // isError?
    if (options.isError) {
        audio.play(audiofx.error);
    }
},
要使用彩色消息,您应该能够使用HTML字符串:

log.addMessage({
    message: '<span style="color: red;">[ERROR]</span>&nbsp;',
    isNewLine: false
});

log.addMessage({
    message: 'the rest of the error message',
    isNewLine: true
});
log.addMessage({
消息:“[错误]”,
isNewLine:false
});
log.addMessage({
消息:“错误消息的其余部分”,
isNewLine:对
});
请随意使用此想法注册您自己的自定义消息框。

我可以为您提供我的建议吗?它以前是一个
textarea
,但我已经将它重构为
div
,代码几乎没有变化

代码的一些要点,可在

用于发送日志消息的自定义函数:

/**
 * Add a message to the gamelog
 * @param {Object} options : allows custom output
 * @param {String} options.message : the message to display
 * @param {Boolean} options.isTimed : does the message has a timestamp in front of it?
 * @param {Boolean} options.isError : is the message an error?
 * @param {Boolean} options.isNewline : start the message on a new line
 */
addMessage: function (options) {
    var instance = ns.instance,
        audio = instance.audio,
        audiofx = audio.settings.fx,
        history = this.areaMessage.html();

    // isTimed?
    options.message = options.isTimed
        ? history + this.fieldClock.val() + ': ' + options.message
        : history + options.message;

    // isNewline?
    if (options.isNewline) {
        options.message = options.message + '<br />';
    }

    // message
    this.areaMessage.html(options.message);
    this.scrollTop(this.areaMessage);

    // isError?
    if (options.isError) {
        audio.play(audiofx.error);
    }
},
要使用彩色消息,您应该能够使用HTML字符串:

log.addMessage({
    message: '<span style="color: red;">[ERROR]</span>&nbsp;',
    isNewLine: false
});

log.addMessage({
    message: 'the rest of the error message',
    isNewLine: true
});
log.addMessage({
消息:“[错误]”,
isNewLine:false
});
log.addMessage({
消息:“错误消息的其余部分”,
isNewLine:对
});

请随意使用此想法注册您自己的自定义消息框。

类似于:
ta.value+=msg.body+“\n”;ta.scrollTop=9e9类似于:
ta.value+=msg.body+“\n”;ta.scrollTop=9e9在yuge日志中可能会变慢;在每次更新中添加Child总比删除所有丰富的html好…是的,你可能是对的!可以说,只需要这一点就可以生存一场比赛。顺便说一句,我喜欢你的高尔夫版本^^@TimVermaelen在花了一些时间考虑你的建议后,我注意到这并不完全是我想要的,因为我缺少一些选项,比如当有人在文本区域内滚动并格式化内容(如单个单词)时停止自动向下滚动(你的建议不起作用)。我想我会创造一个赏金,希望有人知道一个解决这个用例的库。我确信很多人已经面临过类似的问题,尽管我很好奇为什么HTML格式不起作用;在每次更新中添加Child总比删除所有丰富的html好…是的,你可能是对的!可以说,只需要这一点就可以生存一场比赛。顺便说一句,我喜欢你的高尔夫版本^^@TimVermaelen在花了一些时间考虑你的建议后,我注意到这并不完全是我想要的,因为我缺少一些选项,比如当有人在文本区域内滚动并格式化内容(如单个单词)时停止自动向下滚动(你的建议不起作用)。我想我会创造一个赏金,希望有人知道一个解决这个用例的库。我确信很多人已经面临过类似的问题,尽管我很好奇为什么HTML格式不起作用。