JS:选择选项后替换函数

问题描述 投票:-1回答:1

您好,我想在带有选择选项字段的形式中使用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>

它在您第一次获得最佳选择时起作用,但是当我想切换选项时,出现错误或无显示。请您能帮我解决这个问题

javascript laravel function select tinymce
1个回答
2
投票

尝试使用hideshow隐藏您的元素,而不是删除它们。

$(".matheditor-wrapper-math" ).hide();
// or
$(".matheditor-wrapper-math" ).show();
© www.soinside.com 2019 - 2024. All rights reserved.