0
$(function() {
alert($("#fruit").val());
$("#fruit").click(change2());
});
var apple1 = ("<p>The orange is the fruit of the citrus species Citrus × sinensis in the family Rutaceae. The fruit of the Citrus sinensis is called sweet orange to distinguish it from that of the Citrus aurantium, the bitter orange.</p>");
var orange1 = ("<p>LOL I AM AN ORANGE </p>")
var grape1 = ("<p>A grape is a fruiting berry of the deciduous woody vines of the botanical genus Vitis. Grapes can be eaten raw or they can be used for making wine, jam, juice, jelly, grape seed extract, raisins, vinegar, and grape seed oil.</p>");
var strawberry1 = ("<p>The garden strawberry is a widely grown hybrid species of the genus Fragaria. It is cultivated worldwide for its fruit. The fruit is widely appreciated for its characteristic aroma, bright red color, juicy texture, and sweetness.</p>");
var cantaloupe1 = ("<p>Cantaloupe refers to a variety of Cucumis melo, a species in the family Cucurbitaceae. Cantaloupes range in size from 500 g to 5 kg. Originally, cantaloupe referred only to the non-netted, orange-fleshed melons of Europe.</p>");
function change2() {
alert("Test2");
var select = $("#fruit").val();
switch (select) {
case "apple":
$("#description").html(apple1);
alert("apple");
break;
case "orange":
$("#description").html(orange1);
alert("orange");
break;
case "grapes":
$("#description").html(grape1);
alert("grapes");
break;
case "cantaloupe":
$("#description").html(cantaloupe1);
alert.ht("melon");
break;
case "strawberry":
$("#description").html(strawberry1);
alert("straw");
break;
case "none":
alert("reddit is cool");
$("#description").html("<p> wow wow wow much doge </p>" + apple1);
break;
}
alert("end");
}
我試圖在#fruit選擇菜單更改時激活switch語句。出於某種原因,無論我嘗試什麼,我都不起作用。我想將其更改爲var。所以我們在網頁中選擇蘋果,它應該運行switch語句並輸出var apple1。對於deafult而言,它設置爲「none」,因此啓動時會自動運行「none」情況。這只是爲了測試。在jQuery事件中調用函數
*「它不起作用」*:你究竟是什麼意思?發生了什麼,你期望發生什麼?你解釋問題越好,我們就越容易幫助你,對其他人(在未來)也會更容易認識到他們是否有同樣的問題。 –
「它確實有效」,因爲在下拉菜單中選擇不同的值時,函數/ .click函數不會執行。 – Gibson