您好,登錄后才能下訂單哦!
程序要求:
編寫一個(gè)html文件的網(wǎng)頁(yè)代碼,頁(yè)面包含一個(gè)下拉列表框、一個(gè)文本框和一個(gè)按鈕,下拉列表框選擇要去的網(wǎng)站,當(dāng)選擇完畢后文本框中出現(xiàn)對(duì)應(yīng)的網(wǎng)址。點(diǎn)擊確認(rèn)跳轉(zhuǎn)按鈕后訪問(wèn)文本框中出現(xiàn)的網(wǎng)址。
實(shí)現(xiàn)效果:
實(shí)現(xiàn)代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript事件</title> </head> <body> <select id="select_www" onchange="surf()"> <option value="0" selected="selected">請(qǐng)選擇</option> <option value="http://www.baidu.com">百度</option> <option value="http://www.163.com">網(wǎng)易</option> <option value="http://www.qq.com">qq</option> <option value="http://www.sina.com.cn">新浪</option> </select> <input type="text" id="textbox"> <button value="" id="button_www" onclick="jump()">確認(rèn)跳轉(zhuǎn)</button> </body> <script type="text/javascript"> function surf(){ select=document.getElementById("select_www").value; switch(select){ case "http://www.baidu.com" : document.getElementById("textbox").value="http://www.baidu.com"; break; case "http://www.163.com" : document.getElementById("textbox").value="http://www.163.com"; break; case "http://www.qq.com" : document.getElementById("textbox").value="http://www.qq.com"; break; case "http://www.sina.com.cn" : document.getElementById("textbox").value="http://www.sina.com.cn"; break; } } function jump(){ location=document.getElementById("textbox").value; } </script> </html>
總結(jié)
以上所述是小編給大家介紹的JS實(shí)現(xiàn)點(diǎn)擊下拉列表文本框中出現(xiàn)對(duì)應(yīng)的網(wǎng)址,點(diǎn)擊跳轉(zhuǎn)按鈕實(shí)現(xiàn)跳轉(zhuǎn),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)億速云網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。