onclick() jQuery/JavaScript 显示饼图的按钮不起作用


onclick() jQuery/JavaScript Button to display piechart doesn't work

<a data-role="button" data-transition="flip" href="#feedbackmain" inline style="height:120px" type="button" name="feedbackLink">
        <img src="icons/report.png" inline style="height:80px"/><br/>Feedback
</a>

所以我有如上所示的这个按钮,我正在尝试触发它为我打开饼图。问题是我似乎无法让按钮工作。如果可能的话,我还可以在网页加载时创建饼图,但也无法弄清楚如何做到这一点。我的饼图是在jQplot中制作的,生成方式如下:

function drawChart(data) {
     var data = data;
      var options = {
          title: 'Pie Chart',
          seriesDefaults: {
            renderer: jQuery.jqplot.PieRenderer,
            rendererOptions: {
              showDataLabels: true,
              dataLabels: 'value',
              fill: false,
              sliceMargin: 5,
              lineWidth: 5,
              startAngle: 45
            }
          },
          legend: { show:true, location: 'w' }
        };
      $.jqplot('chartDivId', data, options);
    }

现在,我尝试像这样调用该函数:

$(document).ready(function()
    {
    drawChart([[["data1",6],["data2",5],["data3",2]]]);
})

我得到一个透明的框,应该在其中绘制图表,但是...它是透明的。我可以在具有 data-role: page 的同一div 上制作一个带有 onClick 函数的按钮并使其工作,但我宁愿在启动时加载它,因为我需要通过 PHP 从 MySQL 加载 data1,data2,data3 参数。我什至无法与第一个代码片段中显示的按钮联系到以下代码:

$("#feedbackLink").click(function()
        {
        alert("2");
        })
    });

有人知道如何解决这个问题吗?要么获得按钮为我完成此操作,要么让图表与脚本的其余部分一起自动加载。

编辑:我什至将其剥离为:

$(document).ready(function()
    {
        $("#test").click(function()
        {
            alert("2");
        })
})

和按钮:

<div data-role="page" id="page1">
    <input type="button" id="test" value="test"/>
</div>

我基本上删除了整个页面中的其他所有内容,但仍然没有该死的联系人:U

您需要将 id 属性添加到锚点,以便可以使用 JQuery 处理单击事件

<a data-role="button" data-transition="flip" id="feedbackLink" href="#feedbackmain" inline style="height:120px" type="button" name="feedbackLink">
    <img src="icons/report.png" inline style="height:80px"/><br/>Feedback
</a>

此外,您还需要确保事件处理程序编写在 $(document(.ready(( 中

$(document).ready(function(){
    $("#feedbackLink").click(function(){
      alert("2");
    })
});

id属性添加到锚链接,然后尝试...它肯定会起作用

在 jQuery 中,#类似于元素的 ID

$("#feedbackLink").click(function()
        {
        alert("2");
        })
    });