如何在asp.net頁面上放置的控制項上實現左右鍵菜單,同時對之操作(2)
來源:互聯網
上載者:User
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函數中。你就可以輕鬆的加上你想處理的各種功能了。
各位看官,如果不明
vvvvvvvvvvv