您好,我想在带有选择选项字段的形式中使用tinymce和mathlatex,在这里我可以选择数学或文本,我试图使用此代码:
$("#type_c").change(function()
{
var opt = $(this).val();
var conte = document.getElementsByName('content');
var text = document.getElementsByClassName('tox-tinymce');
var maths = document.getElementsByClassName('matheditor-wrapper-math');
switch (opt) {
case "1":
if(maths){
$(".matheditor-wrapper-math" ).remove();
tiny();
}else{
tiny()
}
break;
case "2":
if (text){
$(".tox-tinymce" ).remove();
math()
}else{
math()
}
break;
}
});
和html代码:
<div class="form-group">
<label for="">Question</label>
<input type="text"
class="form-control" name="questionn" id="question" aria-describedby="helpId" placeholder="">
<small id="helpId" class="form-text text-muted">add the question</small>
</div>
<div class="form-group">
<label for="">select the type</label>
<select class="form-control" name="type" id="type">
<option value="1">QE</option>
<option value="2">Tache</option>
<option value="3">Liste</option>
</select>
</div>
<div class="form-group">
<label for="">content type</label>
<select class="form-control" name="type_c" id="type_c">
<option value="">Select the type content</option>
<option value="1">Text</option>
<option value="2">Latex</option>
</select>
</div>
<div class="form-group">
<label for="">content</label>
<textarea class="form-control" name="content" id="content" rows="3"></textarea>
</div>
<input type="hidden" name="m_id" value={{$m_id->id}}>
<button type="submit" class="btn btn-primary">Submit</button>
它在您第一次获得最佳选择时起作用,但是当我想切换选项时,出现错误或无显示。请您能帮我解决这个问题
尝试使用hide
和show
隐藏您的元素,而不是删除它们。
$(".matheditor-wrapper-math" ).hide();
// or
$(".matheditor-wrapper-math" ).show();