function ShowChart() {
var fromDate = $("#fromdate").val().replace(",", "");
var toDate = $("#todate").val().replace(",", "");
var chartType = 'Customers'; // Revenue,Refunds,Customers,Purchases
var chartURL = "<?php echo base_url() . 'merchant/GetChartData/'; ?>";
chartURL += chartType + "/" + fromDate + "/" + toDate + "/";
}
// run it
ShowChart();
HTML:
<ul class="tabs">
<li><a href="#Revenue">Revenue</a></li>
<li><a href="#Refunds">Refunds</a></li>
<li><a href="#Customers">Customers</a></li>
<li><a href="#Purchases">Purchases</a></li>
</ul>
这是我可以通过手动更改chartType
来显示图表的图表设置,但我想自动执行此操作,因此单击链接将更新图表。
我知道可以使用var str = this.href.split("#")[1];
读取和存储href值,但我不确定如何“更改”chartType
的值并在每次点击时“运行”该功能?
答案 0 :(得分:1)
尝试使用.click()
将ShowChart功能附加到使用<a>
选择器的每个.tabs a
标记的点击事件中。然后,只需将chartType
设置为您的split
代码。
function ShowChart() {
var fromDate = $("#fromdate").val().replace(",", "");
var toDate = $("#todate").val().replace(",", "");
var chartType = this.href.split("#")[1]; // Revenue,Refunds,Customers,Purchases
var chartURL = "<?php echo base_url() . 'merchant/GetChartData/'; ?>";
chartURL += chartType + "/" + fromDate + "/" + toDate + "/";
}
// Attach event to every a under .tab
$('.tabs a').click(ShowChart);