我想打开一个新标签页,例如 <a href="http://google.com"
target="_blank">Plant 1</a>
每当点击图表时
Javascript.
总结:
当您点击 Plant 1
时在图表中,带有 google.com
的新选项卡会出现。
当您点击 Tan Thanh
时在图表中,带有 dell.com
的新选项卡会出现。
当您点击 Plant 3
时在图表中,带有 w3schools.com
的新选项卡会出现。
当您点击 Plant 4
时在图表中,带有 simplion.com
的新选项卡会出现。
Demo
HTML:
<div id="chart_div" style="width: 550px; height: 500px;"></div>
Javascript:
google.load("visualization", "1", {
packages: ["corechart"]
});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'link', 'Sales', 'Expenses'],
['Plant 1', 'http://google.com', 1000, 400],
['Tan Thanh', 'http://dell.com', 1170, 460],
['Plant 3', 'http://w3schools.com/', 660, 1120],
['Plant 4', 'http://simplion.com', 1030, 540]
]);
var view = new google.visualization.DataView(data);
view.setColumns([0, 3]);
var options = {
title: 'Company Performance'
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(view, options);
var selectHandler = function (e) {
window.location = data.getValue(chart.getSelection()[0]['row'], 1);
}
// Add our selection handler.
google.visualization.events.addListener(chart, 'select', selectHandler);
}
最佳答案
使用
window.open( data.getValue(chart.getSelection()[0]['row'], 1), options.title, "height=200,width=200");
代替,
window.location = data.getValue(chart.getSelection()[0]['row'], 1);
关于javascript - 如何使用 Javascript 将元素目标添加到我的代码中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24403984/