jQuery刚刚由ajax元素添加
php脚本是jQuery刚刚由ajax元素添加,jquery,Jquery,php脚本是 它向0发出警报,因此无法看到新的div 如何让它看到新的div?您必须等到帖子完成后才能检查长度。这样做: $.post('includes/script.php', $(this).serialize(), function(data) { $('body').append(data); }); alert ($('#new').length) 你怎么称呼它?我在Firefox、Chrome和IE中收到警报1。请注意,“函数”在您的代码片段中拼写错误 $.post('
它向0发出警报,因此无法看到新的div
如何让它看到新的div?您必须等到帖子完成后才能检查长度。这样做:
$.post('includes/script.php', $(this).serialize(), function(data) {
$('body').append(data);
});
alert ($('#new').length)
你怎么称呼它?我在Firefox、Chrome和IE中收到警报1。请注意,“函数”在您的代码片段中拼写错误
$.post('includes/script.php', $(this).serialize(), function(data) {
var newItem = $(data).appendTo('body');
alert (newItem.length);
});
$(文档).ready(函数(){
addnew();
});
函数addnew(){
$('body')。追加('text');
警报($(“#新”).length)
}
我的坏习惯太简单了。更正,找到了。异步:false@Quio如果您能将代码移动到成功处理程序中,它将对您有效。Javascript是一种事件驱动语言。
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready( function() {
addnew();
});
function addnew (){
$('body').append('<div id="new">text</div>');
alert ($('#new').length)
}
</script>