简体   繁体   English

使用单选按钮显示/隐藏tinymce

[英]Show/hide tinymce with radio buttons

I try to show/hide a tinymce with radobutton. 我尝试使用radobutton显示/隐藏tinymce。 Like yes/no. 像是/不是。 So there are two radio buttons. 因此,有两个单选按钮。 yes - will show the tiny mce and no will hide the tinymce. 是的-将显示微小的mce,否将隐藏微小的mce。

I have this: 我有这个:

showing tiny mce: 显示微小的mce:

<div class="form-group">
    @Html.Label(Resources.Entity.Product.PdfMessage, new { @class = "text-bold control-label col-md-2" })
    <div class="col-lg-6 col-md-8 col-sm-10 ">
        @Html.EditorFor(model => mailModel.PdfMessage, new { htmlAttributes = new { @class = "form-control tiny-mce", data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name, id = "tinyMCE" } })
        @Html.ValidationMessageFor(model => mailModel.PdfMessage)
        @*@Html.TextArea("MailProductHandlers_message", mailModel.Message, new { @class = "form-control", @rows = 15 })*@
    </div>
</div>

these are my radio buttons: 这些是我的单选按钮:

<div class="form-group">
    @Html.Label(Resources.Entity.Product.GeneratePDF, new {@class = "text-bold control-label col-md-2" })
    <div class="col-lg-6 col-md-8 col-sm-10 ">

        @Html.Label(Resources.Entity.Product.GeneratePDFYes)  @Html.RadioButtonFor(model => model.IsChecked, "Yes", new { @checked = true, id = "radioButton" })
        @Html.Label(Resources.Entity.Product.GeneratePDFNo)  @Html.RadioButtonFor(model => model.IsChecked, "No", new { @checked = true, id = "radioButton2" })

    </div>
</div>

and this is my javascript: 这是我的javascript:

<script>
    $(document).ready(function () {
        $("input[Id='radioButton']").click(function () {
            if ($(this).is(':checked')) {
                $('#tiny-mce').show();
            }
            else {
                $('#tiny-mce').hide();
            }
        });
    });
</script>

if I do this: $('#mceu_61').hide(); 如果我这样做: $('#mceu_61').hide(); it hides the editor. 它隐藏了编辑器。 but after I press on yes, it shows the editor. 但在按“是”后,它显示了编辑器。 but if I then press No it doesnt hide anymore. 但是,如果我再按“否”,它将不再隐藏。 And I have this: 我有这个:

@Html.EditorFor(model => mailModel.PdfMessage, new { htmlAttributes = new { @class = "form-control tiny-mce", @id = "mceu_61", data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name } })

Your missing an @symbol for the id attribute: Modify your script as well like this: 您缺少id属性的@符号:修改脚本,如下所示:

***EDIT some thing seems off about the radio buttons only one should be checked and they should have the same name ** ***编辑关于单选按钮似乎有些问题,仅应选中一个,并且它们应具有相同的名称**

you can use the # to denote and ID in Jquery by the way instead off looking it up by attribute 您可以使用#来表示Jquery中的ID和ID,而不必按属性查找

EDIT I changed a few things around, I don't think you need two individual ids I grouped them with a class, you should be able to check the on change event from that class instead of checking on both ids 编辑我改变了几件事,我不认为您需要两个单独的ID,我将它们与一个类分组,您应该能够检查该类的on change事件,而不是同时检查两个ID

@Html.EditorFor(model => mailModel.PdfMessage, new { htmlAttributes = new { @class = "form-control tiny-mce", @id = "tinyMCE", @data_lang = System.Globalization.CultureInfo.CurrentUICulture.Name  } })


@Html.RadioButtonFor(model => model.IsChecked, "Yes", new { @checked = true, @class = "pdfchecker" })

// only one should be checked
@Html.RadioButtonFor(model => model.IsChecked, "No", new { @checked = false, @class = "pdfchecker" })



<script>
    // this is short hand for document ready
    $(function () {
        //# is to denote an ID, . is to denote a class in jQuery the change function is hit when a radio button is change check the name to make sure they are apart of the same grouping
        $(".pdfchecker").change(function () {
            if ($(this).is(':checked')) {
                $('#tiny-mce').show();
            }
            else {
                $('#tiny-mce').hide();
            }
   });






</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM