0
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手动更改来显示图表的图表设置,但我想自动执行此操作,因此单击链接将更新图表。

我知道可以读取和存储 href 值,var str = this.href.split("#")[1];但我不确定如何chartType在每次点击时“更改”值并“运行”函数?

4

1 回答 1

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);
于 2013-03-31T12:54:30.907 回答