![](/img/trans.png)
[英]How to disable the ContextMenu but not the right click event in a WebView
[英]Contextmenu right click event
看看這個鏈接,我想獲得點擊表末日元素。 我該怎么做 ? 我將嘗試此代碼,但是沒有用。
例如,當我單擊鼠標右鍵並打開上下文菜單時,我想在文本列中輸入文字。
$("body").on("contextmenu", "table tr", function(e) {
$contextMenu.css({
display: "block",
left: e.pageX,
top: e.pageY
});
console.log($(this));
return false;
});
將$(e.target)
用於表示單擊元素的jquery對象。 否則,只需將e.target
用於普通的舊javascript dom元素。
對於您的情況,要警告列文本,請嘗試以下代碼:
$(function() {
var $contextMenu = $("#contextMenu");
$("body").on("contextmenu", "table tr", function(e) {
$contextMenu.css({
display: "block",
left: e.pageX,
top: e.pageY
});
alert($(e.target).text());
return false;
});
$contextMenu.on("click", "a", function() {
$contextMenu.hide();
});
});
有關event.target的更多信息,請訪問: https : //developer.mozilla.org/en-US/docs/Web/API/Event/target
首先使用TR> TD選擇器
$("table tr >td").on("contextmenu", function(e) { alert($(this).text()); //rest of the statements goes here });
Internet Explorer引入了element.innerText ,其他瀏覽器使用element.textContent 。
$(function() {
$("body").on("contextmenu", "table tr", function(e) {
var target = e.target.parentElement;
var text = target.innerText || target.textContent;
alert(text);
return false;
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.