jQuery运行函数combobox填充多个组合框

时间:2016-03-17 07:01:14

标签: javascript jquery combobox

我有组合框

 <select name="search_category[]"  id="search_category_id">
    <option value="" selected="selected"></option>
    <?php
    $query = "SELECT * FROM t_category ORDER BY category_name ASC";
    $results = mysql_query($query);

    while ($rows = mysql_fetch_assoc(@$results))
    {?>
        <option value="<?php echo $rows['category_id'];?>"><?php echo $rows['category_name'];?></option>
    <?php
    }?>
</select>

<span id="show_sub_categories" align="center">

这是JS

jQuery(document).ready(function($){
    $('#loader').hide();
    $('#show_heading').hide();
$('#search_category_id').change(function(){
    $('#show_sub_categories').fadeOut();
    $('#loader').show();
    $.post("get_chid_categories.php", {
        parent_id: $('#search_category_id').val(),
    }, function(response){

        setTimeout("finishAjax('show_sub_categories', '"+escape(response)+"')", 400);
    });
    return false;
});

function finishAjax(id, response){
 $('#loader').hide();
 $('#show_heading').show();
 $('#'+id).html(unescape(response));
 $('#'+id).fadeIn();
} 

function alert_id()
{
if($('#sub_category_id').val() == '')
alert('Please select a sub category.');
else
alert($('#sub_category_id').val());
return false;
}

如果我有多个具有不同ID的组合框怎么样?

示例:

<select name="search_category[]"  id="search_category_id1">
    <option value="" selected="selected"></option>
    <?php
    $query = "SELECT * FROM t_category ORDER BY category_name ASC";
    $results = mysql_query($query);

    while ($rows = mysql_fetch_assoc(@$results))
    {?>
        <option value="<?php echo $rows['category_id'];?>"><?php echo $rows['category_name'];?></option>
    <?php
    }?>
</select>

<select name="search_category[]"  id="search_category_id2">
    <option value="" selected="selected"></option>
    <?php
    $query = "SELECT * FROM t_category ORDER BY category_name ASC";
    $results = mysql_query($query);

    while ($rows = mysql_fetch_assoc(@$results))
    {?>
        <option value="<?php echo $rows['category_id'];?>"><?php echo $rows['category_name'];?></option>
    <?php
    }?>
</select>

我想要为该2个组合框运行该功能。但是当试图运行代码时,该功能仅针对第一个组合框运行。 (该功能基于第一个组合框填充第二个组合框。)

1 个答案:

答案 0 :(得分:0)

您需要在docker run -dt --cap-add SYS_PTRACE -p 8082:8080 tomcat7-test 处理程序中加载第二个select。示例(未经测试):

$.post.success