简体   繁体   English

如何隐藏和显示另一个选择选项栏的选择选项

[英]how to hide and show select options for another select option bar

i will love to have the solution to this challenge below. 我很乐意在下面找到解决这个挑战的方法。 i want a situation when i select the Doctor option it hides the list of specialist and when i select the specialist it shows the list of specialist. 我想要一种情况,当我选择医生选项时,它会隐藏专家列表,当我选择专家时,它会显示专家列表。 thanks 谢谢

    <tr><td colspan=2 ><strong>Doctor Locator</strong></td></tr>
         <tr><td>
             <?php
                    $doc = 'Doctors';
                    $spel = 'Specialist';
                    $medic = array($doc, $spel);
                    sort ($medic);
                    echo "<select>";
                    foreach ($medic as $m)
                    {
                    echo "<option value=\"$m\">$m</option>";
                    }
                    echo "</select> <br/> ";

            ?>

                <select name="txt_specialize" style="width: 400px; height: 25px">
            <?php
            $specialist = array('Surgeon','Neurosurgeon','','Neurologist','Occupational Medicine Physician','Ophthalmologist',
            'Oral and Maxillofacial Surgeon','Pathologist','Psychiatrist','Podiatrist','Nephrologist','Otolaryngologist',
            'Internal Medicine Physician','Gastroenterologist','Emergency Physicians','Hermatologist','Dermatologist',
            'Anesthesiologist','Immunologist','Orthopaedic Surgeon','Radiation Onconlogist','Gynaecologist','Dentist',
            'Optician','Cardiologist','Pediatrician','Urologist','Diagnostic Radiologist','Pulmonary Medicine Physician',
            'Rheumatologist','Plastic Surgeon');
                sort ($specialist);
                    foreach ($specialist as $s)
                    {
                    echo "<option value=\"$s\">$s</option>";
                    }
                    echo "</select>"

            ?>
            </td></tr>
            <tr><td>

You can easily do this with jQuery. 您可以使用jQuery轻松完成此操作。 If you give the first select an id of "type", you can add the following jQuery: 如果你给第一个选择id为“type”,你可以添加以下jQuery:

        $(document).ready(function(){

            $("select[name='txt_specialize']").hide();

            $("select#type").change(function(){
                if($(this).val() == 'Doctor')
                {
                    $("select[name='txt_specialize']").hide();
                }
                else
                    $("select[name='txt_specialize']").show();
            });

        });

Attach a change event to your first select box. change事件附加到第一个选择框。

http://api.jquery.com/change/ http://api.jquery.com/change/

In the callback, update the selectbox content for your taste. 在回调中,根据您的喜好更新选择框内容。

Add data-attributes to txt_specialize $s and done write script like this: select doctor 将数据属性添加到txt_specialize $ s并完成写脚本:select doctor

$('#doctor').change(function(e){
     var doc = $('#doctor').val();
     $("#specialist option").each(
     function(){
        if ($(this).attr('data-doctor')==doc){
          $(this).show()
        }else{
           $(this).hide()  
        }
     })
})

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

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