Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在导航栏中将父对象()显示为html_Javascript_Jquery - Fatal编程技术网

Javascript 在导航栏中将父对象()显示为html

Javascript 在导航栏中将父对象()显示为html,javascript,jquery,Javascript,Jquery,我的页面上有一堆按钮元素,在mouseover上,我想获取所选按钮的祖先,然后在导航栏中将它们显示为html或数组。这是我目前为止的javascript,它根本不起作用。有什么想法吗 $( document ).ready(function() { $("*").on.("mouseover", function() { var treeTraversal = $(this).parents().map(function(){ return this.tagNam

我的页面上有一堆按钮元素,在
mouseover
上,我想获取所选按钮的祖先,然后在导航栏中将它们显示为html或数组。这是我目前为止的javascript,它根本不起作用。有什么想法吗

$( document ).ready(function() {
    $("*").on.("mouseover", function() {
      var treeTraversal = $(this).parents().map(function(){
      return this.tagName;}).get().join(", ");
      $("<span>").after("<h2>" + treeTraversal + "<h2>");
});
$(文档).ready(函数(){
$(“*”).on.(“鼠标悬停”,函数(){
var treeTraversal=$(this.parents().map(function()){
返回此.tagName;}).get().join(“,”;
$(“”)。在(“+treeTraversal+”)之后;
});

删除上的
之后的句点

$(文档).ready(函数(){
$(“*”).on(“鼠标悬停”,函数(){
var treeTraversal=$(this.parents().map(function()){
返回此.tagName;
}).get().join(“,”);
警觉的(treeTraversal);
$(“”)。在(“+treeTraversal+”)之后;
});
});

api.jquery.com›事件›事件处理程序附件
jQuery 加载。。。 .on()方法将事件处理程序附加到jQuery对象中当前选定的元素集。。。 www.w3schools.com/jquery/event_on.asp
W3学校 加载。。。 从jQuery 1.7版开始,on()方法是bind()、live()和delegate()方法的新替代品。。。 www.andismith.com/blog/2011/11/on-and-off/
2011年11月10日-随着11月3日jQuery1.7的发布,出现了两种附加事件处理程序的新方法--.on()和.off()。虽然可能不是最常用的。。。 stackoverflow.com/questions/8110934/direct-vs-delegate-jquery-on
2011年11月13日-我试图理解直接……案例1之间的特殊区别( 直接):$(“div#target span.green”)。在(“单击”,function(){…})上;。 stackoverflow.com/../jquery对具有多个事件处理程序的方法执行。。。
2011年12月22日-情况正好相反。你应该写:$(“table.planning_grid”)。在({mouseenter:function(){//Handle mouseenter…}上,mouseleave:function()。。。 stackoverflow.com/questions/../jquery关于多个选择器上的方法
2011年12月11日-如果您试图使用.on(),以便可以侦听在您进行初始.on()调用后可能创建的DOM对象上的事件,那么最。。。 stackoverflow.com/../jquery-event-handler-not-working-on-dynamic-co。。。
2013年2月26日-您必须添加选择器参数,否则事件将直接绑定而不是委派,这仅在元素已存在时有效(因此。。。 weblog.west wind.com/posts/2013/../用jQuery替换jQuerylive。。。