【发布时间】:2011-11-15 16:15:57
【问题描述】:
所以我尝试禁用一些 <li> 元素上的链接,这些元素已使用 .load() 函数从另一个页面加载,但由于某种原因,我无法影响这些列表项。
var from_post = false;
$(document).ready(function() {
//so this is the function that loads in data from another page
$("#gallery").load('http://localhost/index.php/site/gallerys_avalible/ #gallerys_avalible'), function() {
console.log('hello');
// sense there are no other li elliments on the page i thought this
// would be okay. but this function never gets called, i've moved it
// all over i just recently attached it to the load function thinking
// that maybe if the load was not complete it would not run, but i
// have had no luck.
$('li').click(function (e) {
e.preventDefault();
console.log("I have been clicked!");
return false;
});
};
$('#addNew').click(function () {
console.log('i got called');
$('#new_form').fadeIn(1000);
});
$('form').submit(function() {
if(from_post) {
//submit form
return true;
} else {
//dont submit form.
return false;
}
});
任何帮助将不胜感激,哦,另一件事是我可以通过 firebug 运行此功能,并且可以 100% 正常工作。所以我很难过。
【问题讨论】:
-
你所拥有的看起来很合理,但我在你的代码中没有看到关于禁用链接的任何内容。
-
有人刚刚回答了我的问题 .live() 有效。 :) 但他们出于某种原因删除了答案。但感谢大家的帮助。
-
他试图阻止默认点击事件。
-
是的,这是我的答案,我在再次查看您的代码后删除了...
标签: javascript jquery ajax function jquery-selectors