<script>
var data = prompt("What year would you like the data for?");
if (data == 1901) {
alert("26 thousand per million for males and 23 for females ");
} else if (data == 1910) {
alert("23 thousand per million for males and 18 for females");
} else if (data == 1920) {
alert("19 thousand per million for males and 15 for females");
} else if (data == 1930) {
alert("17 thousand per million for males and 14.5 for females");
} else if (data == 1940) {
alert("20 thousand per million for males and 15 for females");
} else if (data == 1950) {
alert("15 thousand per million for males and 11 for females");
} else if (data == 1960) {
alert("14.5 thousand per million for males and 9.5 for females");
} else if (data == 1970) {
alert("14 thousand per million for males and 8 for females");
} else if (data == 1980) {
alert("13 thousand per million for males and 5 for females");
} else if (data == 1990) {
alert("10 thousand per million for males and 6 for females");
} else if (data == 2000) {
alert("7 thousand per million for males and 5.2 for females");
} else if (data == 2010) {
alert("7 thousand per million for males and 4.9 for females");
}else alert ("please enter a valid year from the chart.");
</script>
這是我的javascript這顯然開放的提示和要求的日期,但我想這提示上點擊按鈕被激活,例如我想Javascript代碼鏈接到一個按鈕
要獲取日期[點擊此處] ----->「您希望獲得哪些數據?」
我該怎麼做。此按鈕也需要進入html。
在函數內部獲取該代碼。有按鈕的點擊事件調用該函數。 – Renan
你可能想要做一些研究並試一試。查看此頁面上的「相關」側邊欄。告訴我們你的嘗試和錯誤。 「詢問代碼的問題必須對所解決的問題有最小的理解,包括**嘗試的解決方案**,**爲什麼他們不工作**,以及預期的結果。」 – showdev
非常感謝你的幫助。愚蠢的我忘記把它放在一個函數 –