假设我有一段带有此 html 标记的文本:
<p id="myId">Some text <span>some other text</span></p>
当我在段落上的任意位置右键单击时,如何获取 id
的值?
更新:
我只是将值传递给函数,我没有提及以免复杂化。
最佳答案
然后为 p
编写一个 mousedown 处理程序
$('p').on('mousedown', function(e){
if(e.which== 3){
alert(this.id)
}
})
演示:Fiddle
关于javascript - 从右键单击的段落中获取 id 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19508288/