亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

代碼鏡像。替換文本的簡單方法?

代碼鏡像。替換文本的簡單方法?

慕婉清6462132 2023-08-18 17:50:00
我使用CodeMirror?(5.58.2)來編輯文本。new_cm?=?CodeMirror.fromTextArea(textarea_obj,?param);但是在文本區域中,我可以輕松替換文本,只需執行以下操作obj.value = obj.value.replace( /123/g, '3210');?我可以在 CodeMirror 中做類似的事情嗎?無需向用戶提出任何接口請求。只是一個簡單的“Make Replace”按鈕和帶有正則表達式模式的代碼。
查看完整描述

2 回答

?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

這是一個例子......


// start the editor instance  

const new_cm = CodeMirror.fromTextArea(textarea_obj, param);


// get the entire editor text from CodeMirror editor  

let text = new_cm.getValue();


// edit the text, for example  

text = text.replace(/abc/g, '');


// set the text back to the editor  

new_cm.setValue(text);


查看完整回答
反對 回復 2023-08-18
?
千巷貓影

TA貢獻1829條經驗 獲得超7個贊

我嘗試了一下,效果非常好:


<!doctype html>

<html>

  <head>

<title>CodeMirror</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="UTF-8">

<link rel=stylesheet href="https://CodeMirror.net/doc/docs.css">

<link rel="stylesheet" href="" id="modeFile">

<link rel="stylesheet" href="colorpicker/addon/codemirror-colorpicker.css" />

<link rel="stylesheet" href="colorpicker/addon/codemirror-colorpicker.css" />

<script src="https://CodeMirror.net/addon/hint/anyword-hint.js" id="anyword"></script>

<link rel="stylesheet" href="https://CodeMirror.net/lib/codemirror.css">

<link rel="stylesheet" href="https://CodeMirror.net/addon/hint/show-hint.css">

<link rel="stylesheet" href="https://CodeMirror.net/addon/dialog/dialog.css">

<link rel="stylesheet" href="https://CodeMirror.net/addon/search/matchesonscrollbar.css">

<script type="text/javascript" src="colorpicker/addon/codemirror-colorpicker.js"></script>

<script type="text/javascript" src="colorpicker/addon/codemirror-colorpicker.js"></script>

<script src="https://CodeMirror.net/lib/codemirror.js"></script>

<script src="https://CodeMirror.net/addon/edit/closetag.js"></script>

<script src="https://CodeMirror.net/addon/hint/show-hint.js"></script>

<script src="https://CodeMirror.net/addon/hint/sql-hint.js"></script>

 <script src="https://CodeMirror.net/addon/mode/loadmode.js"></script>

<script src="https://CodeMirror.net/mode/meta.js"></script>

<script src="https://CodeMirror.net/addon/hint/xml-hint.js"></script>

<script src="https://CodeMirror.net/addon/hint/html-hint.js"></script>

<script src="https://CodeMirror.net/addon/search/jump-to-line.js"></script>

<script src="https://CodeMirror.net/addon/hint/javascript-hint.js"></script>

<script src="https://CodeMirror.net/mode/xml/xml.js"></script>

<script src="https://CodeMirror.net/mode/javascript/javascript.js"></script>

<script src="https://CodeMirror.net/mode/css/css.js"></script>

<script src="https://CodeMirror.net/mode/htmlmixed/htmlmixed.js"></script>

<script src="https://CodeMirror.net/addon/dialog/dialog.js"></script> 

<script src="https://CodeMirror.net/addon/search/searchcursor.js"></script>

<script src="https://CodeMirror.net/addon/search/search.js"></script>

<script src="https://CodeMirror.net/addon/fold/xml-fold.js"></script>

<script src="https://CodeMirror.net/addon/scroll/annotatescrollbar.js"></script> 

<script src="https://CodeMirror.net/addon/search/matchesonscrollbar.js"></script>

<script src="https://CodeMirror.net/addon/runmode/runmode.js"></script>

<script src=" https://CodeMirror.net/addon/runmode/colorize.js"></script>

</head>

<body>

<div id="editor"></div>

<button onclick="find()">find</button>

<button onclick="replace()">replace</button>

<button onclick="JTL()"Jump-To-Line</button>

<button onclick="undo()">undo</button>

<button onclick="redo()">redo</button>

<script>

function find() {

    

    editor.execCommand('find');

  }

  function undo() {

    

    editor.execCommand('undo');

  }

  function redo() {

    

    editor.execCommand('redo');

  }

  function Replace() {

    

    editor.execCommand('replace');

  }

  function JTL() {

    

    editor.execCommand('jumpToLine');

  }

</script>

<script>

var editor = CodeMirror(document.getElementById('editor'),{

      mode: 'text/html',

      matchBrackets: true,

      lineNumbers: true,

      });

</script>

</body>

</html>


查看完整回答
反對 回復 2023-08-18
  • 2 回答
  • 0 關注
  • 192 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號