gpt4 book ai didi

javascript - jquery 函数未在 ajax 函数内部调用

转载 作者:行者123 更新时间:2023-11-28 12:07:43 27 4
gpt4 key购买 nike

所以我尝试禁用某些 <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% 正常。所以我很难过。

最佳答案

您过早地关闭了对 .load() 的调用。你有:

$("#gallery").load('http://...'), function() {

这只是调用 load,然后声明一个函数。但是,该函数未绑定(bind)到成功处理程序,并且永远不会执行。您需要将 ) 放在函数声明的另一侧,以便该函数作为参数包含在您的加载调用中:

$("#gallery").load('http://...', function() {
...
});

解决这个问题,您的代码就可以工作了:http://jsfiddle.net/gilly3/WdqDY/

关于javascript - jquery 函数未在 ajax 函数内部调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7393990/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com