2012-12-26 19 views
10

在jsfiddle中,他們可以選擇在左側選項中設置no wrap(head),no wrap(body),OnDomReadyOnLoad。在我的程序中設置no wrap(head)條件。它的工作很好。但是我如何轉換爲HTML文件。同等條件下,我需要在我的HTML文件中設置在html頭部和身體中的Now condition狀況

演示:JSFIDDLE

這裏我設置no-wrap(head),我如何設置HTML文件相同的條件no-wrap(head)

這裏我完整的代碼

<html> 
<head> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script> 
<script type="text/javascript" src="a.js"></script> 
<script type="text/javascript"> 
google.load('visualization', '1', {packages: ['corechart']}); 
google.setOnLoadCallback(drawVisualization); 

function drawVisualization() { 
var data = google.visualization.arrayToDataTable([ 
    ['Country', 'Popularity'], 
    ['Germany', 200], 
    ['United States', 300], 
    ['Brazil', 400], 
    ['Canada', 500], 
    ['France', 600], 
    ['Russia', 700] 
]); 

// this chart is drawn in a visible div and then immediately hidden 
var chart1 = new google.visualization.PieChart(document.getElementById('chart_1')); 

google.visualization.events.addListener(chart1, 'ready', function() { 
    // hide the div when done drawing 
    document.getElementById('chart_1').style.display = 'none'; 

    // create an event listener for the button that shows the chart 
    document.getElementById('clickMe1').onclick = function() { 
     document.getElementById('chart_1').style.display = 'block'; 
    } 
}); 

// show the div before you draw 
document.getElementById('chart_1').style.display = 'block'; 

chart1.draw(data, { 
    height: 300, 
    width: 400, 
    title: 'Chart 1' 
}); 


// this chart only gets drawn when the button is clicked 
var chart2 = new google.visualization.PieChart(document.getElementById('chart_2')); 

// create an event listener for the button that shows the chart 
document.getElementById('clickMe2').onclick = function() { 
    document.getElementById('chart_2').style.display = 'block'; 
    chart2.draw(data, { 
     height: 300, 
     width: 400, 
     title: 'Chart 2' 
    });    
} 
} 
</script> 
<style type="text/css"> 
#visualization path { 
cursor: pointer 
} 
</style> 

    </head> 
    <body> 
<input type="button" value="Show chart 1" id="clickMe1" /> 
<input type="button" value="Show chart 2" id="clickMe2" /> 
<div id="chart_1" style="display: none"></div> 
<div id="chart_2" style="display: none"></div> 
    </body> 
</html> 

謝謝提醒。

回答

7

這只是意味着把你的JavaScript <head>標籤之間

從文檔頁面

JSFiddle Documentation

Reference

+0

嗨,我在這裏更新我的html代碼。在我的代碼中,所有的javascript都放在head標籤中。但爲什麼它不工作? – Selvamani

+0

您在這行上錯過了一個關閉'script'標記'

3

它只是意味着腳本中的<html>

JSFiddle Docs<head>部分添加,

沒有包(頭):不換行JavaScript代碼,將其放置在<head> 部分

Here是你migh什麼演示不要使用(所有的HTML在一個地方)。

+0

謝謝你,可以在知道,在IE8文檔模式下,該代碼工作你的機器?如果不是我可以糾正它,因爲那個小提琴在IE8文檔模式下工作。 – Selvamani

+0

不,它不,但我記得,這是因爲谷歌圖表有'IE8'文檔模式的一些問題,[**檢查此**](http://stackoverflow.com/questions/13081894/ie8-不支持谷歌圖表餅圖) –

+0

http://jsfiddle.net/3KxFZ/2/但這裏第二個餅圖在ie8文檔模式下可見,怎麼樣? – Selvamani

相關問題