我正在尝试在查询中不使用toggleClass函数来切换两个类。 这是要定义类的元素。
<a class="btn btn-floating waves-effect waves-light blue show-editor"><i class="material-icons">add</i></a>
最初,我有班级节目编辑。单击此锚标记时,我将启动绑定到textarea的tinyMce编辑器。
$('.show-editor').on('click', function(e){
e.preventDefault();
console.log('show-editor class clicked');
tinymce.init({
selector: '#comment',
height: 200,
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools codesample toc'
],
toolbar1: 'undo redo | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
toolbar2: 'print preview media | forecolor backcolor emoticons | codesample',
image_advtab: true,
templates: [
{ title: 'Test template 1', content: 'Test 1' },
{ title: 'Test template 2', content: 'Test 2' }
],
content_css: [
'//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
'//www.tinymce.com/css/codepen.min.css'
]
});
$('.show-editor').addClass('remove-editor');
$('.remove-editor').removeClass('show-editor');
});
$('.remove-editor').on('click', function(e){
e.preventDefault();
console.log('removed-editor class clicked');
tinyMCE.remove();
$('.remove-editor').addClass('show-editor');
$('.show-editor').removeClass('remove-editor');
});
上面的代码非常适合第一次点击。 tinyMCE编辑器启动,我收到一条消息“show-editor class clicked”。我看到show-editor类通过检查DOM来删除和删除编辑器类添加到元素,但是当我再次单击锚标记时,编辑器仍然保留,我在控制台中再次收到相同的消息。我在这做什么错?