JavaScript/CodeMirror-刷新文本区域 [英] JavaScript / CodeMirror - refresh textarea

查看:657
本文介绍了JavaScript/CodeMirror-刷新文本区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用CodeMirror 2中的刷新功能?

How do I use the refresh function from CodeMirror 2?

refresh()

如果您的代码需要更改 编辑器元素的大小(窗口 调整大小已被监听),或者 取消隐藏它,您可能应该遵循 通过调用此方法来确保 CodeMirror仍然看起来像

If your code does something to change the size of the editor element (window resizes are already listened for), or unhides it, you should probably follow up by calling this method to ensure CodeMirror is still looking as intended.

我想在单击链接后刷新所有文本区域

I want to refresh all textareas after a link is clicked

我尝试过

  $('.CodeMirror').each(function(){
    getElementById($(this).attr('id')).refresh();
  });

但是它不起作用....

but it doesn't work....

推荐答案

refresh方法(与所有其他CodeMirror方法一样)不在DOM节点上,而是在创建编辑器时返回的实例对象上(通过调用CodeMirror或CodeMirror.fromTextArea).因此,您必须将它们存储在某个地方才能工作.

The refresh method (just like all other CodeMirror methods) does not live on the DOM node, but on the instance object that's returned when you create the editor (by calling CodeMirror or CodeMirror.fromTextArea). So you'll have to store those somewhere for this to work.

这篇关于JavaScript/CodeMirror-刷新文本区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆