如何在asp.net頁面上放置的控制項上實現左右鍵菜單,同時對之操作(2)

來源:互聯網
上載者:User
CSDN - 文檔中心 - .NET    
標題     如何在asp.net頁面上放置的控制項上實現左右鍵菜單,同時對之操作(2)    lyx123(原作)
關鍵字     asp.net,右鍵菜單


上文說到菜單被建立出來了,現在要說的是第二部分的:

(2),選擇菜單,點擊菜單

選擇菜單和點擊菜單實際上時滑鼠的MouseMove和Click事件。在上文提到的menustyle裡面,我是通過JavaScript提供的window.createPopup函數來實現快顯功能表,快顯功能表的內容為一個表格。在表格中的每一項都提供了MouseMove和Click事件。

在MouseMove事件發生的時候,我就讓他顯示出不同的風格。

當發生Click事件的時候,就調用函數fnclick,使之發生我們的需要的任務。現在具體來介紹menustyle()函數。

function menuStyle(){

 if(window.navigator.appName == "Microsoft Internet Explorer" && window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE") + 5, window.navigator.appVersion.indexOf("MSIE") + 8) >= 5.5)

      isIe = 1;

else

isIe = 0;

if(isIe){

        menuContent = '<table id="rightMenu" width="0" height="0" cellspacing="0" cellpadding="0" style="font:menu;color:menutext;"><tr height="1"><td style="background:black" colspan="4"></td></tr><tr height="10"><td style="background:black"></td><td style="background:Snow"><table cellspacing="0" cellpadding="0" nowrap style="font:menu;color:menutext;cursor:default;">';   //這一行是畫了個表格,從下面開始,添加表格裡面的項目,同時給出了MouseOver的風格等。最關鍵的一個地方是onClick事件發生調用的函數為parent.fnclickmenu,特別提醒的是調用的是父視窗的函數。

        for(m=0;m<menuItems.length;m++){

                     if(menuItems[m][0] && menuItems[m][2])

                            menuContent += '<tr height="17" onMouseOver="this.style.background=/'#9999cc/';this.style.color=/'menutext/';" onMouseOut="this.style.background=/'Snow/';this.style.color=/'menutext/';" onClick="parent.fnclickmenu(/''+menuItems[m][1]+'/')"<td style="background:threedface" width="1" nowrap></td><td width="21" nowrap><img src="' + menuItems[m][2] + '"></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:threedface" width="1" nowrap></td></tr>';

                     else if(menuItems[m][0])

                            menuContent += '<tr height="17" onMouseOver="this.style.background=/'#9999cc/';this.style.color=/'menutext/';" onMouseOut="this.style.background=/'Snow/';this.style.color=/'menutext/';" onClick="parent.fnclickmenu(/''+menuItems[m][1]+'/')"><td style="background:threedface" width="1" nowrap></td><td width="21" nowrap></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:threedface" width="1" nowrap></td></tr>';

                     else

                            menuContent += '<tr><td colspan="5" height="4"></td></tr><tr><td colspan="5"><table cellspacing="0"><tr><td width="2" height="1"></td><td width="0" height="1" style="background:threedshadow"></td><td width="2" height="1"></td></tr><tr><td width="2" height="1"></td><td width="100%" height="1" style="background:threedhighlight"></td><td width="2" height="1"></td></tr></table></td></tr><tr><td colspan="5" height="3"></td></tr>';

                     }

                     menuContent += '</table></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight"></td><td style="background:threedface"></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedshadow" colspan="3"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threeddarkshadow" colspan="5"></td></tr></table>';

                     //下面就彈出了一個菜單。

                     menuPopup = window.createPopup();

            //菜單裡面的東西為上面畫出的表格。

                     menuPopup.document.body.innerHTML = menuContent;

結合上文的ShowMenu(),函數,就明白了如何?快顯功能表功能的方法了。在fnclickmenu函數中。你就可以輕鬆的加上你想處理的各種功能了。

      各位看官,如果不明白還希望能夠和我交流。Email:l_yx123@sina.com.cn

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.