简体   繁体   中英

How can I make my checkbox appear and disappear?

I have the following CSS and HTML:

<select id="ContentID" name="ContentID">
   <option selected="selected" value="00">Menu</option>
   <option value="01">Topic</option>
</select>
<input id="htmlEdit" type="checkbox" />

$("#ContentID")
.val($.cookie("ContentID_dropdown"))
.change(function () {
   $.cookie("ContentID_dropdown", $(this).val(), { expires: 365, path: '/' });
});

Is there a way that I can make the checkbox be visible if the "Menu" is selected and not visible if anything else is selected? I am not sure how to do this. I guess I need something that will take into account that the value could be one or other based on the cookie and then the user could go in and change it.

You just need to check the value and respond accordingly

$("#ContentID")
.val($.cookie("ContentID_dropdown"))
.change(function () {
   if($(this).val() == "00")
      $("#htmlEdit").hide();
   else
      $("#htmlEdit").show();
   $.cookie("ContentID_dropdown", $(this).val(), { expires: 365, path: '/' });
});

You need to look whether another option has been selected, something like:

$("#ContentID")
.val($.cookie("ContentID_dropdown"))
.change(function () {
    $.cookie("ContentID_dropdown", $(this).val(), { expires: 365, path: '/' });
    $("#htmlEdit").toggle($(this).val() == "00");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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