1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title></title>6 </Head>7 <Body>8 <inputtype= "button"value= "Click to select"ID= "BT"/><BR/>9 <Selectname=""ID= "ss">Ten <optionvalue= "1">Fried Durian</option> One <optionvalue= "2">Braised Stinky Tofu</option> A <optionvalue= "3">Steamed Rotten Eggs</option> - <optionvalue= "4">Salted duck eggs with salad</option> - <optionvalue= "5"ID= "OP1">Stir-fried chili pepper</option> the </Select> - <Script> - //Package ID Get element - functionmy$ (ID) { + returndocument.getElementById (ID); - } + //Get button elements by ID, register click events, add event handlers A my$ ("BT"). onclick= function () { at //get clicked on the selected menu element set selected property value - my$ ("OP1"). Selected= true; - }; - </Script> - </Body> - </HTML>
JavaScript DOM Action case click button to select Menu