jQuery: hide and show an input element

后端 未结 6 2122
情话喂你
情话喂你 2021-02-19 09:42

I\'m trying to do is hiding/showing a certain input object if a select value is checked.

Code in JSFiddle

The HTML part of the code is here:

<         


        
6条回答
  •  太阳男子
    2021-02-19 09:46

    I typically factor out the hide/show logic:

    function foobar(){
        if($(this).val() == "Other"){
            $("#add_fields_placeholderValue").show();
        }
        else{
            $("#add_fields_placeholderValue").hide();
        }
    }
    

    and call it when the page loads.

    $(document).ready(function(){
        foobar();
        $("#add_fields_placeholder").change(function(){
            foobar();
        });
    });
    

    but i'd be curious to see what other folks usually do.

提交回复
热议问题