在我的 PHP 应用程序中,我使用了 2 个 php 文件。
chart.php - 页面包含一个 google 图表。
<div id="chart_div" style="height:100%;width:100%"> </div> <script type="text/javascript"> google.charts.load('current', {'packages':['bar']}); google.charts.setOnLoadCallback(drawStuff); function drawStuff() { var data = new google.visualization.arrayToDataTable([ ['Opening Move', 'Percentage'], ["King's pawn (e4)", 44], ["Queen's pawn (d4)", 31], ["Knight to King 3 (Nf3)", 12], ["Queen's bishop pawn (c4)", 10], ['Other', 3] ]); var options = { title: 'Chess opening moves', width: 900, legend: { position: 'none' }, chart: { title: 'Chess opening moves', subtitle: 'popularity by percentage' }, bars: 'horizontal', // Required for Material Bar Charts. axes: { x: { 0: { side: 'top', label: 'Percentage'} // Top x-axis. } }, bar: { groupWidth: "90%" } }; var chart = new google.charts.Bar(document.getElementById('chart_div')); chart.draw(data, options); google.visualization.events.addListener(chart, 'select', selectHandler); }; function selectHandler() { window.location.href = "chart.php"; } </script>
<强>2。 index.php - 我将 chart.php 包含在 div 中的主页
<div style="width:40%">
require_once 'chart.php';
</div>
点击 index.php 页面中的图表,它会调用 selectHandler()
并重定向到 chart.php。
问题是,chart.php 中的图表(从 index.php 重定向后)显示为小尺寸,类似于 index.php 中的图表显示。刷新 chart.php 后,它将以正确的大小显示图表。
除了使用 location.reload()
之外,jquery 中是否有任何通过重新加载来刷新页面的函数。
谁能帮我解决这个问题?提前致谢。
最佳答案
尝试重新绘制图表,
在您的选择处理程序上使用内联函数,
这样您仍然可以访问您的图表、数据和选项。
google.visualization.events.addListener(chart, 'select', function () {
window.location.href = "chart.php";
chart.draw(data, options);
});
关于javascript - 重新加载然后在同一函数jquery中刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51442213/