Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jquery ready()中找不到上一个插入的元素_Javascript_Jquery - Fatal编程技术网

Javascript 在jquery ready()中找不到上一个插入的元素

Javascript 在jquery ready()中找不到上一个插入的元素,javascript,jquery,Javascript,Jquery,我的代码不起作用,后面的脚本似乎找不到前面插入的元素 我更新了前三个Anowner的基本语法错误,但它似乎仍然不起作用 代码: <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></scrip

我的代码不起作用,后面的脚本似乎找不到前面插入的元素

我更新了前三个Anowner的基本语法错误,但它似乎仍然不起作用

代码:

<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.min.js"></script>
<script type="text/javascript"> 
$(document).ready( function() {
     $('#menu').html('<a href="page4.html" class="dynamicLoad">ddd</a>');
 });  

$(document).ready( function() {
        $( 'a.dynamicLoad' ).click( function( e ) {
            e.preventDefault();   // prevent the browser from following the link
            e.stopPropagation();  // prevent the browser from following the link
            $( '#myDiv' ).load( $( this ).attr( 'href' ) );
        });
});
</script>

</head>
<body>


<div id="menu">mymenu</div>
<div id="myDiv">aaaaaaaaaaaa</div>
</body>
</html>

$(文档).ready(函数(){
$(“#菜单”).html(“”);
});  
$(文档).ready(函数(){
$('a.dynamicLoad')。单击(函数(e){
e、 preventDefault();//防止浏览器跟随链接
e、 stopPropagation();//阻止浏览器跟随链接
$('#myDiv').load($(this.attr('href'));
});
});
我的菜单
aaaaaaaaaaaa

innerHTML
语句更改为以下内容:

$('#menu').html("<a href='page4.html' class='dynamicLoad'>ddd</a>");
});
$('#menu').html(“”);
});
因为当前您的语句有多个语法错误

另外,是Javascript而不是jQuery——它是jQuery的等价物吗


这是一张工作票

您的整个代码现在应该如下所示:

HTML:

<div id="menu">mymenu</div>
<div id="myDiv">aaaaaaaaaaaa</div>
$(document).ready( function() {
     $('#menu').html("<a href='page4.html' class='dynamicLoad'>ddd</a>");
     $( 'a.dynamicLoad' ).click( function( e ) {
           e.preventDefault();   // prevent the browser from following the link
           e.stopPropagation();  // prevent the browser from following the link
           $( '#myDiv' ).load( $( this ).attr( 'href' ) );
     });
});
mymenu
aaaaaaaaaaaa
jQuery:

<div id="menu">mymenu</div>
<div id="myDiv">aaaaaaaaaaaa</div>
$(document).ready( function() {
     $('#menu').html("<a href='page4.html' class='dynamicLoad'>ddd</a>");
     $( 'a.dynamicLoad' ).click( function( e ) {
           e.preventDefault();   // prevent the browser from following the link
           e.stopPropagation();  // prevent the browser from following the link
           $( '#myDiv' ).load( $( this ).attr( 'href' ) );
     });
});
$(文档).ready(函数(){
$(“#菜单”).html(“”);
$('a.dynamicLoad')。单击(函数(e){
e、 preventDefault();//防止浏览器跟随链接
e、 stopPropagation();//阻止浏览器跟随链接
$('#myDiv').load($(this.attr('href'));
});
});
它应该是
html()

jquery中的
innerHTML
==
html()

然后退出您的

$('#menu').html(“”);
//------^^^^---这里
您有一个quotes
问题,并改用:

$('#菜单').html('');
您应该使用jQuery的
.html()
方法,而不是
innerHTML
,因为jQuery简化了一些javascript函数。jQuery仍然是javascript,但它有不同的和一些简化的语法

$('#menu').html("<a href='page4.html' class='dynamicLoad'>ddd</a>");
$('#menu').html(“”);

使用W3链接时要小心(阅读:避免)。div html不能是一个html吗?仍然无法看到链接页面或如何获取加载页面的正文?然后将正文设置为div?–user125697,找不到您的答案。感谢user125679,在修复了基本语法问题后,目前可以找到link元素,但另一个问题是:加载页面无法在div#myDiv中显示。