jquery 獲取當前物件及相關的一些處理問題
阿新 • • 發佈:2018-11-26
demo1: 需求:同時獲取 分類和週期 兩個指標的編碼,傳到後臺。 程式碼: jsp: <div class="choose-tab text-center"> <i class="tips">分類:</i> <span class="statisticType cur" code="1">資料總條數</span> <span class="statisticType" code="2">資料容量</span> <span class="statisticType mr40" code="3">資料表數</span> <i class="tips">週期:</i> <span class="statisticalPeriod cur" code="1">最近12個月</span> <span class="statisticalPeriod" code="2">最近一個月</span> <span class="statisticalPeriod" code="3">最近一週</span> </div>
js :
$('.statisticType').on('click', function () { var currentObj = $(this); $(".statisticType").removeClass("cur"); currentObj.addClass("cur"); var statisticType = currentObj.attr('code'); var statisticalPeriod = ''; var objArray = $('.statisticalPeriod'); for (var i = 0; i < objArray.length; i++) { if ($(objArray[i]).hasClass('cur')) { statisticalPeriod = $(objArray[i]).attr('code'); break; } } if ($.trim(statisticType) == '' && $.trim(statisticalPeriod) == '') { layer.msg("引數為空!"); return false; } trendInDataVolume(statisticType, statisticalPeriod); });