在我的文档的 HEAD 中,我加载了 jQuery.js 以及 blockUI jQuery 插件。
然后在 PHP 中,我使用常规 AJAX 将其他 PHP 内容加载到 DIV 中。在原始的 PHP 中,jQuery 和 blockUI 插件工作得很好,但在任何 ajax 加载的 div 中,jQuery 和 blockUI 都完全没有任何作用。没有控制台错误,没有警告 - 没有。
我是一个 jQuery 初学者,我在这个主题上找到的其他文章都无法让我超越解决这个问题的能力,所以我正在帮助其他人。在我下面的代码中,您会看到我在 live() 上进行了一些尝试...
这是加载到 DIV 中的我的 PHP 文件的顶部
<script type="text/javascript">
$(document).ready(function() {
$('#crazy').live('click',function() {
$.blockUI({ message: $('#question'), css: { width: '275px' } });
});
$('#yes').live('click',function() {
// update the block message
$.blockUI({ message: "<h1>Remote call in progress...</h1>" });
$.ajax({
url: 'wait.php',
cache: false,
complete: function() {
// unblock when remote call returns
$.unblockUI();
}
});
});
$('#no').live('click',function() {
$.unblockUI();
return false;
});
});
</script>
这是该 PHP 文件中的 HTML(加载到 DIV 中):
<input id="crazy" type="submit" value="Show Dialog" />
<div id="question" style="display:none; cursor: default">
<h1>Would you like to contine?.</h1>
<input type="button" id="yes" value="Yes" />
<input type="button" id="no" value="No" />
</div>