時間聯動

guyun發表於2019-03-21
<%if !empty($timeData)%>

更新時間:

請選擇年份 $val %>

selected="selected"> 年請選擇月份 selected="selected"  > 月

<%/if%>

// 獲取   年 -- 月

var timeDataJson=<%$timeDataJson%>;

$(function(){

​    // 聯動

​    $("select[name='year']").change(function(){

var year = $(this).val();

var html = ' 請選擇月份 ';

for(var i in timeDataJson[year]){

​            html += ''+timeDataJson [year][i]+' 月 ';

}

​        $("select[name='month']").html(html);

​    });

// 跳轉的

​    $("select[name='month']").change(function(){

​        var year = $("select[name='year'] option:selected").val();

​        var month = $("select[name='month'] option:selected").val();

var get = "?year="  + year +"&month="+ month+'<%$monthLink%>';

​        window.location="xxxx"+ get ;

})

});

// 年份、月份

$arrtime = $t_arr = $timeData = array();

$arrtime = get_brochures_time();

foreach ($arrtime as $k => $v) {

​    $t_arr = explode('-', $v['create_time']);

​    $timeData[$t_arr[0]][] = $t_arr[1];

}

$tplEngine->assign("timeData", $timeData);

$tplEngine->assign("timeDataJson", json_encode($timeData));

$selectYear = mysql_escape_string($_REQUEST["year"]);

$selectMonth = mysql_escape_string($_REQUEST["month"]);

$_params = $params;

if ($_params["month"]) {

​    unset($_params["year"]);

​    unset($_params["month"]);

}

$monthLink = http_build_query($_params);

$monthLink = empty($monthLink) ? "" : "&{$monthLink}";

$tplEngine->assign ("monthLink", $monthLink);// 更新時間

$tplEngine->assign("selectYear", $selectYear);

$tplEngine->assign("selectMonth", $selectMonth);
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章