js實現(xiàn)網(wǎng)頁多級級聯(lián)菜單代碼
本文實例講述了js實現(xiàn)網(wǎng)頁多級級聯(lián)菜單。分享給大家供大家參考。具體如下:
這是大家在網(wǎng)頁上經(jīng)常會見到的級聯(lián)菜單特效,不過這一個代碼是由JS來實現(xiàn),將級聯(lián)菜單中的內(nèi)容保存在了JS數(shù)組中,為了頁面美觀,本次還美化了一下表格邊框,整體看上去更和諧實用了,多級的下拉菜單對網(wǎng)頁設(shè)計來說比較實用。
運行效果如下圖所示:
在線演示地址如下:
http://demo.jb51.net/js/2015/js-table-select-menu-style-codes/
具體代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>多級級聯(lián)菜單</title> <script type="text/javascript"> var arr2 = new Array(4); arr2["數(shù)碼設(shè)備"] = new Array("數(shù)碼相機","打印機"); arr2["家用電器"] = new Array("電視機","電冰箱"); arr2["禮品工藝"] = new Array("鮮花","彩帶"); function removeinfo(classMenu){//將下拉框各選項清空 for (var i=0; i < classMenu.options.length; i++){ classMenu.options[i]=null; } } function changeMenu(classList,classMenu){ removeinfo(classMenu) for (var i=0; i < classList.length; i++){ classMenu[i]=new Option(classList[i],classList[i]); } } </script> </head> <body style="font-size:12px"> <table width="487" height="333" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center" valign="top"><br> <br> <br> <br> <br> <table width="86%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#6699CC"> <form name="form1"> <tr bgcolor="#FFFFFF"> <td height="22" align="right">所屬類別:</td> <td height="22" align="left"><select name="類別" id="類別" onChange="changeMenu(arr2[document.form1.類別.options[document.form1.類別.selectedIndex].text],document.form1.分類);"> <option selected>數(shù)碼設(shè)備</option> <option>家用電器</option> <option>禮品工藝</option> </select> <select name="分類" id="分類"> <option>數(shù)碼相機</option> <option>打印機</option> </select></td> </tr> <tr bgcolor="#FFFFFF"> <td height="22" align="right">商品名稱:</td> <td height="22" align="left"><input name="商品名稱" type="text" id="商品名稱" size="30" maxlength="50"></td> </tr> <tr bgcolor="#FFFFFF"> <td height="22" align="right">會員價:</td> <td height="22" align="left"><input name="會員價" type="text" id="會員價" size="10"></td> </tr> <tr bgcolor="#FFFFFF"> <td height="22" align="right">提供廠商:</td> <td height="22" align="left"><input name="提供廠商" type="text" id="提供廠商" size="30" maxlength="50"></td> </tr> <tr bgcolor="#FFFFFF"> <td height="22" align="right">商品簡介:</td> <td height="22" align="left"><textarea name="商品簡介" cols="35" rows="4" id="商品簡介"></textarea></td> </tr> <tr bgcolor="#FFFFFF"> <td height="22" align="right">商品數(shù)量:</td> <td height="22" align="left"><input name="商品數(shù)量" type="text" id="商品數(shù)量" size="10"></td> </tr> <tr bgcolor="#FFFFFF"> <td height="22" colspan="2" align="center"><input name="add" type="submit" id="add2" value="添 加"> <input type="reset" name="Submit2" value="重 置"></td> </tr> </form> </table></td> </tr> </table> </body> </html>
希望本文所述對大家的javascript程序設(shè)計有所幫助。
相關(guān)文章
動態(tài)創(chuàng)建的表格單元格中的事件實現(xiàn)代碼
好久沒有搞網(wǎng)頁了,今天重新弄了一個 ,做個動態(tài)表格,具體的實現(xiàn)代碼,大家可以自己寫吧2008-12-12JavaScript的for循環(huán)中嵌套一個點擊事件的問題解決
本文主要介紹了JavaScript的for循環(huán)中嵌套一個點擊事件點擊一次彈出多個相同的值的解決方法,具有很好的參考價值。下面跟著小編一起來看下吧2017-03-03JavaScript實現(xiàn)仿網(wǎng)易通行證表單驗證
這篇文章主要介紹了JavaScript實現(xiàn)仿網(wǎng)易通行證表單驗證,十分的實用,有需要的小伙伴可以參考下。2015-05-05javascript中parseInt()函數(shù)的定義和用法分析
這篇文章主要介紹了javascript中parseInt()函數(shù)的定義和用法,較為詳細的分析了parseInt()函數(shù)的定義及具體用法,以及參數(shù)使用時的注意事項,需要的朋友可以參考下2014-12-12webpack-cli在webpack打包中的作用小結(jié)
webpack?是打包代碼時依賴的核心內(nèi)容,而?webpack-cli?是一個用來在命令行中運行?webpack?的工具,那么webpack-cli在webpack打包中的作用是什么,本文就詳細的介紹一下,感興趣的可以了解一下2022-04-04