2014-02-13 39 views
0

嗨我希望我的網站有多個上下文菜單,每個菜單都可以在div內單擊鼠標右鍵。 (不同div的不同菜單)。問題是我迄今發現的菜單沒有允許我使用這個網站5力下載鏈接:我想讓我的網站有多個上下文菜單

<a href="Title Blue.png" download="Title Blue.png">Download Title Picture</a> 

我想這是該鏈接指向我的上下文菜單中的項目之一。

我發現了這段腳本,但它不起作用,因爲它裏面有語法錯誤。

<script> 
$(document).bind(「contextmenu」,(e)) { 
    e.preventDefault();     // To prevent the default context menu. 
    $(「#cntnr」).css(「left」, e.pageX); // For updating the menu position. 
    $(「#cntnr」).css(「top」, e.pageY); // 
    $(「#cntnr」).fadeIn(500, startFocusOut()); // For bringing the context menu in picture. 
}; 
function startFocusOut() { 
    $(document).on(「click」, function() { 
     $(「#cntnr」).hide(500);    // To hide the context menu 
     $(document).off(「click」);   
    }); 
} 
$(「#items > li」).click(function() { 
    $(「#op」).text(「You have selected 「 + $(this).text()); // Performing the selected function. 
}); 
</script>" 

另一半就是這將是我的HTML 5的下載鏈接兼容標準的HTML列表:

<span id=」op」>Demo Time</span> // For showing output. 
    <div id=’cntnr’>       // Context menu container. 
    <ul id=’items’>      // List of items in context menu. 
     <li>Item1</li>      // Items to show in context menu. 
     <li>Item2</li> 
     <li>Item3</li> 
     <li>Item4</li> 
     <li>Item5</li> 
    </ul> 
    </div> 

任何人都可以找出錯誤或者給我開了使用內我的HTML 5鏈接不同的上下文菜單

感謝

+0

任何控制檯錯誤?用螢火蟲檢查它,看看錯誤。並且也改變這個引號「像這樣」 – mehmetakifalp

回答

0

首先,你需要將所有的在你的代碼'"

HTML:

<a href="Title Blue.png" download="Title Blue.png">Download Title Picture</a> 

<span id='op'>Demo Time</span> 
    <div id='cntnr'>       
    <ul id='items'>      
     <li>Item1</li>      
     <li>Item2</li> 
     <li>Item3</li> 
     <li>Item4</li> 
     <li>Item5</li> 
    </ul> 
    </div> 

JS:

$(document).bind('contextmenu',function(e) { 
    e.preventDefault();     // To prevent the default context menu. 
    $('#cntnr').css('left', e.pageX); // For updating the menu position. 
    $('#cntnr').css('top', e.pageY); // 
    $('#cntnr').fadeIn(500, startFocusOut()); // For bringing the context menu in picture. 
}); 
function startFocusOut() { 
    $(document).on('click', function() { 
     $('#cntnr').hide(500);    // To hide the context menu 
     $(document).off('click');   
    }); 
} 
$('#items > li').click(function() { 
    $('#op').text('You have selected ' + $(this).text()); // Performing the selected function. 
}); 

Working Fiddle here

+0

這很好,但它不能用作上下文菜單!? – Michael

+0

我怎麼把這些片段放在一起成爲一個html文件?我以爲我知道,但是當我把這些片斷放在什麼都不會發生時。我沒有做過嗎? – Michael

+0

@ user3304628把上面顯示的'

相關問題