php – onclick()jQuery / JavaScript按钮显示饼图不起作用
发布时间:2020-12-13 16:17:21 所属栏目:PHP教程 来源:网络整理
导读: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 所以我有如上所示的这个按钮,我试图触发它为我
<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处理click事件
<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"); }) }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |