javascript无法使用动态添加的标签 [英] javascript not working on dynamically added tabs

查看:111
本文介绍了javascript无法使用动态添加的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临一个奇怪的错误,涉及javascript。我已经使用jquery ui选项卡动态添加和删除我的网站中的选项卡,该选项卡的内容包含两个按钮,当鼠标悬停消失,并在底部的相关链接的鼠标左侧可见。此鼠标悬停在第一个默认选项卡正常工作,但不是为动态添加的选项卡。当我mouseover的新选项卡的内容的效果是不会发生。这是一个小提琴

I am facing a strange bug at the moment, involving javascript. I have used jquery ui tabs to dynamically add and remove tabs in my website, the content of the tab contains two buttons which upon mouseover dissappear and become visible on mouseleave of the relevant link at the bottom. This mouseover is working fine for the first default tab but not for dynamically added tabs. when i mouseover the content of the new tab the effect is not happening. Here is a fiddle

http://jsfiddle.net / Hunain / E2nJa /
这个小提琴不是我的结果,不包含我的问题,所以请阅读我的上述语句正确,因为我解释了问题
i使用以下代码for mouseover

http://jsfiddle.net/Hunain/E2nJa/ this fiddle is not exact as my result and doesn't contain my issue so please read my above statement correctly, because i have explained the issue i have used following code for mouseover

$("#butt").mouseenter(function () {
            $("#butt").css("visibility","hidden");
          })
          $("#info").mouseleave(function () {
            $("#butt").css("visibility","visible");
          });


推荐答案

您正在将事件绑定到文档加载和添加按钮绑定后的事件。因此,事件不会与稍后添加的元素绑定。

添加按钮后应绑定事件。

You are binding the event on document load and adding button after the binding the event. So event will not bind with the element which added later.
You should bind event after adding buttons.

这篇关于javascript无法使用动态添加的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆