jquery select下拉列表更改其他下拉列表的值

时间:2016-12-13 17:15:25

标签: php jquery wordpress

我选择更改选择下拉列表的其他值时,我有这个下拉选择选项。我在jquery中使用onchange。我的问题是,当我选择苹果下拉列表时,苹果产品列表会出现,这是可以的。现在,当我选择三星时,它不会改变三星产品的价值。这是我的代码

<script type="text/javascript">
    jQuery(document).ready(function($) {
        /*$("#phoneBrand").change(function () {
            var end = this.value;
            var firstDropVal = $('#data-original-index').val();
            alert(firstDropVal);
        });*/

        $("#phoneBrand").on('change', function(){
            var phoneBrand = $("#phoneBrand").val();

            if(phoneBrand == "apple"){
                alert(phoneBrand);
                <?php
                // All Option
                //echo '<option value="">'.$houzez_local['all_model'].'</option>';
                $prop_type = get_terms (
                    array(
                        "property_feature"
                    ),
                    array(
                        'orderby' => 'name',
                        'order' => 'ASC',
                        'hide_empty' => true,
                        'parent' => 0
                    )
                );

                //houzez_hirarchical_options('property_feature', $prop_type, $type );

                ?>

                //var pModel = "<?php echo $pModel;?>";
                //alert(pModel);


                $("div").each(function(i) {
                    var dropdown = $("<select>");
                    <?php foreach($prop_type as $model): ?>
                    <?php
                        $pName = $model->name;
                        $pSlug = $model->slug;
                        $pModel = $model->description;
                    ?>
                    <?php if($pModel == "apple"): ?>

                    dropdown.append($('<option>', {
                        value:'<?php echo $pSlug; ?>',
                        text:'<?php echo $pName;?>'
                    }));
                    <?php endif; ?>
                    <?php endforeach; ?>
                    $("#phoneModel").replaceWith(dropdown);

                });

            }else if(phoneBrand == "blackberry"){        
              //$("#age_boys").show();
               alert('test');
            }else if(phoneBrand == "htc"){

            }else if(phoneBrand == "huawai"){

            }else if(phoneBrand == "lg"){

            }else if(phoneBrand == "microsoft"){

            }else if(phoneBrand == "nokia"){

            }else if(phoneBrand == "samsung"){
                alert(phoneBrand);
                <?php
                    // All Option
                    //echo '<option value="">'.$houzez_local['all_model'].'</option>';

                    $prop_type = get_terms (
                        array(
                            "property_feature"
                        ),
                        array(
                            'orderby' => 'name',
                            'order' => 'ASC',
                            'hide_empty' => true,
                            'parent' => 0
                        )
                    );

                    //houzez_hirarchical_options('property_feature', $prop_type, $type );
                ?>

                    //var pModel = "<?php echo $pModel;?>";
                    //alert(pModel);

                $( "div" ).each(function(i) {
                    var dropdown = $("<select id='samsung'>");
                    <?php foreach($prop_type as $model): ?>
                    <?php
                        $pName = $model->name;
                        $pSlug = $model->slug;
                        $pModel = $model->description;
                    ?>
                    <?php if($pModel == "samsung"): ?>
                        dropdown.append($('<option>', {
                            value:'<?php echo $pSlug; ?>',
                            text:'<?php echo $pName;?>'
                        }));
                    <?php endif; ?>
                    <?php endforeach; ?>
                    $("#phoneModel").replaceWith(dropdown);


                });


            }
        });


    });
</script>

现在我的html选择下拉列表是由wordpress中的主题houzez构建的

<?php if( $adv_show_hide['type'] != 1 ) { ?>
                <div class="col-sm-3 col-xs-12">
                    <div class="form-group" >
                        <select  id="phoneModel" name="feature" class="selectpicker " data-live-search="false" data-live-search-style="begins">
                            <?php
                            // All Option
                            echo '<option  value="">'.$houzez_local['all_model'].'</option>';

                            $prop_type = get_terms (
                                array(
                                    "property_feature"
                                ),
                                array(
                                    'orderby' => 'name',
                                    'order' => 'ASC',
                                    'hide_empty' => true,
                                    'parent' => 0
                                )
                            );

                            houzez_hirarchical_options('property_feature', $prop_type, $type);


                            ?>
                        </select>
                    </div>
                </div>
                <?php } ?>

有人可以帮我解决这个问题吗?它只会在选择下拉列表后更改值。

以下是截图图片enter image description here

非常感谢任何帮助。 TIA。我正在使用wordpress

0 个答案:

没有答案