我已经接管了我公司网站的开发。当 card_filter div 中的选择框值发生更改时,将运行以下 javascript。
$("#cards_filter select").change(function(e) {
var form = $(this);
var serdata = form.serialize();
var field_name = $(this).attr("name");
var field_value = $(this).val();
//Reset the selectors and keep the one that triggered filter
$('#cards_filter').find('select').val(function(index,value){
if($(this).attr("name") == field_name){
return field_value;
} else {
return "-1";
}
});
}
我想要它,所以当产品选择选项不会被重置而收藏、艺术家和类别选择框会被重置时。
<form id="cards_filter" method="post" action="" name="cards_filter">
<?php echo get_product_selector("products_filter"); ?>
<?php echo get_collection_selector("products_filter"); ?>
<?php echo get_artist_selector("products_filter"); ?>
<?php echo get_category_selector("products_filter"); ?>
</form>
每个选择器的库中都有以下函数
function get_product_selector($form_name) {
if (isset($_SESSION['loggedin']['cur_product'])) {
$curr = $_SESSION['loggedin']['cur_product'];
} else {
$curr = -1;
}
$rtn = "";
$rtn .= '<select id="product" name="product">';
$rtn .= '<option value="-1"';
if ($curr == -1) {
$rtn .= ' selected';
}
$rtn .= '>Select a Product</option>';
$DB = new mysql_db();
$DB->sql_connect();
$q = "SELECT * FROM type order by type_title asc";
$DB->query($q);
if ($DB->get_num_rows()) {
$results = $DB->fetch_all_rows(MYSQL_ASSOC, NULL);
foreach ($results as $key => $row) {
$rtn .= '<option value="' . $row['Type_ID'] . '"';
if ($curr == $row['Type_ID']) {
$rtn .= ' selected';
}
$rtn .= '>' . trim($row['Type_Title']) . '</option>';
}
}
$rtn .= '</select>';
return $rtn;
}