fancybox里面的jquery没有工作
我在fancybox中面临着jquery的问题。 基本上我有一个通过ajax呈现的表单,它已被加载到fancybox中。 但问题是,jquery对fancybox加载的表单不起作用:(但是当我转到实际的表单页面时它工作正常。
我在这里找到了类似的问题http://groups.google.com/group/fancybox/browse_thread/thread/fe6f9cad7b42df79他说使用绝对引用…我甚至试过了,但没有运气。
你们中的任何人都遇到过类似的问题吗?
这是我的jquery代码
$(document).ready(function() { $("input#user_username").click(function(e){ alert("asaadasd"); }); // this works fine when called through the form loaded in the page, but doesn't when the form is loaded within fancybox $("a#login-link, a#login-link2, a#signup-link, a#signup-link2").fancybox({ 'scrolling' : 'no', 'titleShow' : false }); });
任何帮助?
如果您的表单是通过ajax加载的,那么click
事件将不会绑定到document.ready
因为当时它不在文档中。 请改用live()
。 这会将事件绑定到文档中的当前元素和将来元素。
$("input#user_username").live("click", function(e) { alert("asaadasd"); });
您现在应该使用.on()(因为不推荐使用)…
$(document).on("click", "input#user_username", function(e) { alert("asaadasd"); });