HTML5 contextmenu - 单击菜单项时访问最初单击的元素(HTML5 contextmenu - Access originally clicked element when menu item is clicked)
我正在试用最新版本的Firefox中的HTML5 contextmenu项目(目前只支持它的浏览器)。 当我从上下文菜单中单击菜单项时,如何访问在生成菜单时单击的原始元素?
用例将显示项目列表,并且您希望用户对特定项目执行操作。 从菜单中单击操作后,您需要一种方法来确定最初单击列表中的哪个元素以生成菜单。
I'm experimenting with the HTML5 contextmenu item in the latest version of Firefox (only browser that currently supports it). When I click on a menu item from the context menu how can I access the original element that was clicked when the menu was spawned?
The use case would be displaying a list of items and you want the user to perform an action on a particular item. Once the action is clicked from the menu you need a way to determine what element in the list was originally clicked on to spawn the menu.
原文:https://stackoverflow.com/questions/12135385
更新时间:2019-12-19 03:38
最满意答案
只需将它保存在像this.cte = arguments[0]; 然后检索它document.getElementById('testitem').cte
Just save it somewhere like this.cte = arguments[0]; then retrieve it later document.getElementById('testitem').cte
相关问答
您在Plunker中遇到的错误是由于在路径末端拍了“.js”。 不要这样做。 (你没有在你在问题中显示的代码中执行此操作,但在你的plunker中引入了这个问题。)你也做了这个答案所建议的,这是一个糟糕的建议,因为你正在使用它的垫片jquery-contextmenu返回undefined对于模块值。 所以将它分配给$会使$ undefined。 一旦我从你的plunker(我分叉 )编辑这些问题,你的问题中的错误就不会发生。 The errors you got in your Plunker
...
您需要创建selector:选项选择表格单元格。 然后在回调中这将是您单击的单元格。 $(function() {
$(".context-menu-one").contextMenu({
selector: 'td',
callback: function(key, options) {
var content = $(this).text();
alert("You clicked on: " + cont
...
使用$(e.target)表示单击元素的jquery对象。 否则只需将e.target用于普通的旧javascript dom元素。 在您的情况下,要提醒列文本,请尝试以下代码: $(function() {
var $contextMenu = $("#contextMenu");
$("body").on("contextmenu", "table tr", function(e) {
$contextMenu.css({
display: "block",
...
这是对的,哈哈哈...... 花一个小时解决你的问题。 但是,你可以在这里看到我的答案。 $(function() {
$.ajax({
url: 'https://jsonplaceholder.typicode.com/posts/1/comments',
type: 'get',
dataType: 'json',
success: function(data) {
let s = d
...
只需将它保存在像this.cte = arguments[0]; 然后检索它document.getElementById('testitem').cte http://jsfiddle.net/GALmp/4/ Just save it somewhere like this.cte = arguments[0]; then retrieve it later document.getElementById('testitem').cte http://jsfiddle.net/GALmp/4/
...
尝试设置目标控件的ContextMenuService.Placement属性,这里是一个XAML示例:
Padding="10 5"
Background="Lime"
ContextMenuService.Placement="Right"
Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Center"
...
当我点击第一个ContextMenu的项目时如何显示另一个ContextMenu? 我不知道你希望ContextMenu有多深,但是对于两个级别你可以有一个布尔标志,在两种情况之间进行选择,这将从onContextItemSelected更新: boolean flag = true;
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo me
...
您无法以模式方式显示标准菜单。 这不是菜单的工作方式。 如果需要模态选择,则显示模态对话框。 例如,将可能的选项放在一个单选按钮组中,并且只允许在用户做出满足您的选择时关闭模式对话框。 You cannot show standard menus in a modal way as you hope to do. That's just not how menus work. If you want a modal selection then show a modal dialog. Place
...
这意味着您在UI中执行了太多代码并阻止了UI线程。 UI线程尚未得到缓解。 只有当您释放UI线程时,它才能关闭弹出菜单。 您所要做的就是将耗时的任务卸载到其他线程并保持UI线程空闲。 使用任务并行库是卸载任务的推荐方法。 看一下Task.Run和Task.Factory.StartNew方法。 It means that you're executing too much code in UI and blocking the UI thread. UI thread hasn't been re
...
info.targetView是RelativeLayout,而不是TextView。 将android:id属性添加到你的标题TextView(例如android:id =“@ android:id / title”)然后通过以下方式获取字符串值: String title = ((TextView) info.targetView.findViewById(android.R.id.title)).getText();
info.targetView is a RelativeLayout,
...