Checkbox ace.js(在线编辑器)

时间:2018-05-28 14:23:38

标签: javascript

我正在使用ace.js并且有一些主题。基本主题是黑暗主题,我有一个改变主题的复选框。但前两次,当我点击复选框时,主题正在改变,但随后,他们不会改变。问题仅在于主题。

感谢您的帮助。



    var eh = ace.edit("htmlEditor");
 eh.setTheme("ace/theme/monokai");
 eh.session.setMode("ace/mode/html");
 document.getElementById('htmlEditor').style.fontSize='15px';

 var ec = ace.edit("cssEditor");
 ec.setTheme("ace/theme/monokai");
 ec.session.setMode("ace/mode/css");
 document.getElementById('cssEditor').style.fontSize='15px';

 eh.getSession().on('change', function() {
  update();
})
  ec.getSession().on('change', function() {
  update();
})
function update() {
var res = document.getElementById('result').contentWindow.document;
res.open();
res.write('<style>' + ec.getValue() + '</style>');

res.write(eh.getValue());
res.close();
}
update();

function showTheme() {
      var eh = ace.edit("htmlEditor");
  var cbox = document.getElementById('checkbox');
  if (cbox.checked == false) {
      eh.setTheme('ace/theme/tomorrow.css');
  }
else {
     eh.setTheme('ace/theme/monokai');
}
}
showTheme();
&#13;
*{
  padding: 0;
  margin: 0;
}
#htmlEditor {
    height: 100%;
    min-height: 50vh;
    width: 33%;
    display: inline-block;
}
#cssEditor {
    height: 100%;
    min-height: 50vh;
    width: 33%;
    display: inline-block;
}
#container {
    height: 100%;
    width: auto;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    padding: 0 0 0 1%;
}
#result {
    min-height: 424px;
    position: relative;
}
 body {
   background-color: #afafaf;
  }
  #title-of-textarea {
    display: flex;
  }
  #title-css {
    margin: auto;
    padding-right: 35%;
  }
  #header-code {
    display: flex;
  }
  .mnu-code {
    display: flex;
    list-style-type: none;
    padding: 0 0 0 2%;
  }
.mnu-code li {
    padding-left: 5%;
}
#menu-code {
    width: 20%;
    cursor: pointer;
}
#settings {
    margin: 0 0 0 auto;
    padding: 0 5% 0 0;
}
#header-code {
    padding: 1% 0 1% 0;
}
#set {
    cursor: pointer;
}
.container {
    display: block;
    position: relative;
    padding-left: 35px;
    margin-bottom: 12px;
    cursor: pointer;
    font-size: 22px;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Hide the browser's default checkbox */
.container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

/* Create a custom checkbox */
.checkmark {
    position: absolute;
    top: 0;
    left: 0;
    height: 25px;
    width: 25px;
    background-color: #eee;
}

/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
    background-color: #ccc;
}

/* When the checkbox is checked, add a blue background */
.container input:checked ~ .checkmark {
    background-color: #2196F3;
}

/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

/* Show the checkmark when checked */
.container input:checked ~ .checkmark:after {
    display: block;
}

/* Style the checkmark/indicator */
.container .checkmark:after {
    left: 9px;
    top: 5px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 3px 3px 0;
    -webkit-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    transform: rotate(45deg);
}
&#13;
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.3/ace.js"></script>
</head>
			
		  <body>
                </div>
                <div id="header-code">
                     <div id="menu-code">
                     	<ul class="mnu-code">
                     		<li>Проиграть</li>
                     		<li>Сохранить</li>
                     		<li>Поменять вид</li>
</ul>
</div>
<div id="settings">
	<span id="set" onclick="openMenu()">Настройки
		<p>
		<label class="container">One
  <input type="checkbox" id="checkbox" checked="" onclick="showTheme()">
  <span class="checkmark"></span>
</label>
		<p></p>
		<p></p>
	</span>
</div>
                </div>
		  	<div id="container">
		  		<div id="title-of-textarea">
		  		<div id="title-Html">
		  			<h1>HTML</h1>
		  		</div>
	  		<div id="title-css">
		  			<h1>CSS</h1>
		  		</div>
		  	</div>
<div id="htmlEditor"></div>	 
<div id="cssEditor"></div>
</div> 
<iframe id="result" frameborder="0"></iframe>
&#13;
&#13;
&#13;

0 个答案:

没有答案