前端頁面使用ace插件優化腳本


html頁面:<pre id="editor" style="width: 100%;height: 800px;"></pre>(注:必須設置高度)

function getScriptHightLight(){
  ace.config.set("basePath", "vendors/ace-build/src-min");
  ace.require("ace/ext/beautify");
  var editor = ace.edit("editor");
  if($scope.store&&$scope.store.scriptContent){
    editor.setValue($scope.store.scriptContent); //設置內容
    if($scope.oper==="detail"){
      editor.setReadOnly(true); //只讀
    }else{
      editor.setReadOnly(false); //只讀
    }
  }else{
    editor.setValue('');//沒有值設置為空
  }
  editor.setOption("wrap", "free") //自動換行
  editor.setShowPrintMargin(false); //設置打印線
  editor.session.setMode("ace/mode/sh");
  editor.setTheme("ace/theme/vibrant_ink"); //引入的模板
  editor.setHighlightActiveLine(true); //設置高亮
  editor.setOptions({
    enableBasicAutocompletion: true,
    enableSnippets: true,
    enableLiveAutocompletion: true
  });
  editor.on('change', function () {//更新腳本事件
    $timeout(function () {
      $scope.$apply(function () {
        var value = editor.getValue();
        $scope.store.scriptContent=value;
      });
    });
  });
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM