如何用jQuery绑定附加的html?
我正在加载HTML内容并将其附加到一个DIV中。当然,问题是HTML没有绑定 因为我没有点击任何东西,所以我不能使用如何用jQuery绑定附加的html?,jquery,Jquery,我正在加载HTML内容并将其附加到一个DIV中。当然,问题是HTML没有绑定 因为我没有点击任何东西,所以我不能使用jQuery.live或jQuery.bind(我想) 这是我的密码 // Load directory content and display list function loadDirContent(current_path,new_dir) { // Load new content in browser window jQuery.ajax({
jQuery.live
或jQuery.bind
(我想)
这是我的密码
// Load directory content and display list
function loadDirContent(current_path,new_dir)
{
// Load new content in browser window
jQuery.ajax({
type: "POST",
url: "../wp-content/plugins/wp-filebrowser/fileBrowser.php",
dataType: 'html',
data: {current_path: current_path, new_dir: new_dir},
success: function(html){
jQuery("#fileBrowser").html(html); // Append new content
}
});
}
如何绑定这个新的HTML,以便对添加的内容运行jQuery
我在使用Ajax上传插件时遇到了这个问题。它从表单中获取数据,但任何$\u POST数据都保留为空。这仅在使用my loadDirContent函数“重新加载页面”后发生
更新
我在表格中有以下输入:
相对url;?>" />
每次我在文件浏览器中进入一个目录时,current\u path
都会更新
调用uploader.php
函数。在uploader.php中,我有以下命令:$this->current\u path=$\u POST['current\u path'];
问题是,
$\u POST['current\u path']
是空的。您可能需要检查我收到的解决方案。这两个都是很好的答案(我标记了帮助我的答案)。从您正在做的事情来看,您可能希望在添加内容后为其重新分配处理程序。$()。live和$().delegate将同时处理click以外的事件。您将处理程序绑定到哪个事件
此外,如果live/delegate真的不起作用,则始终可以在成功回调中绑定处理程序
例如:
// function for doing event binding:
function bindHandlers(root) {
// do any event binding here, only selecting elements within the provided root
$('.something', root).click(...);
$('.something-else', root).hover(..., ...);
};
// bind all children of the document on dom ready
$(function() { bindHandlers(document); });
// Load directory content and display list
function loadDirContent(current_path,new_dir)
{
// Load new content in browser window
jQuery.ajax({
type: "POST",
url: "../wp-content/plugins/wp-filebrowser/fileBrowser.php",
dataType: 'html',
data: {current_path: current_path, new_dir: new_dir},
success: function(html){
// append the new stuff and attach handlers
bindHandlers($('#fileBrowser').html(html));
}
});
}
只是想一想:你可以
jQuery(#fileBrowser”).html(html)
而不是empty()
和append()
。什么是“HTML未绑定”?您希望绑定到哪个对象的什么事件?@B:谢谢。少一条指令:)@E:我制作了一个文件浏览器界面。当我单击一个新文件夹时,整个界面都会重新加载,从而获取新的HTML。这是使用jQuery进行的。但当我将此数据附加到DIV时,Ajax Uplaoder plugin无法获取表单中的所有数据。因此,我认为这是因为新内容未绑定。在成功回调时如何绑定它?我添加了一个示例…它创建了一个通用函数,将处理程序附加到给定根元素中的元素。在dom加载时,您可以对文档运行它,并在成功的ajax操作时运行它操作,您可以针对新标记运行它。