Javascript jQuery:n子选择器抛出";“未定义”;撞击现场
Javascript jQuery:n子选择器抛出";“未定义”;撞击现场,javascript,jquery,Javascript,Jquery,$('#mapid').val($(“.firstbox ul li:n个子(“+mapi+”)).class())正在返回一个无限循环的未定义错误 我甚至试过这样做:$('#mapid').val($(“.firstbox ul li:nth child(2)”).class())和相同的错误发生 元素无疑是存在的,脚本位于页面底部。不,我不使用Wordpress(我看到这是一个关于错误的常见主题) 以下是HTML: <div id="map-box" class="firstbox"&
$('#mapid').val($(“.firstbox ul li:n个子(“+mapi+”)).class())代码>正在返回一个无限循环的未定义错误
我甚至试过这样做:$('#mapid').val($(“.firstbox ul li:nth child(2)”).class())代码>和相同的错误发生
元素无疑是存在的,脚本位于页面底部。不,我不使用Wordpress(我看到这是一个关于错误的常见主题)
以下是HTML:
<div id="map-box" class="firstbox">
<ul>
<li class="14" id="thelimit">
<div class="left">
<h1>The Limit</h1>
<span class="inf">A branching map. A mix-n match of alot of themes into one map. <p>Recommended Players: 3<br />
Author: <a href="http://www.minecraftforum.net/user/18586-timetoslide/" target="_new">timetoslide</a></p></span>
</div>
<div class="right" style="position: relative">
<div style="width: 250px; height: 120; z-index: 6; position: absolute; top: 0px; height: 120px; left: 35px; cursor: pointer" class="righthover"></div>
<div style="background: url('maps/thelimit.jpg'); width:250px;height:150px;overfow:hidden;border:none;position: relative; z-index: 1">
<div style="background: url('img/vignette.png') no-repeat center center; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; z-index: 2"></div>
<div class="seeList" style="width: 100%; height: 100%; background: url(img/cbg.png) repeat; color: white; font-family: Georgia, 'Times New Roman'; font-size: 24px; margin: 0; padding: 0; font-style: italic; text-align: center; z-index: 1; display: none;"><div style="padding: 20px; padding-top: 40px;">See full list of maps...</div></div>
<img src="img/border.png" style="z-index: 3" />
<div class="directions" style="z-index: 5"></div>
</div>
</div>
</li>
<li class="13" id="lavaseaofsurvival">
<div class="left">
<h1>Lava Sea of Survival</h1>
<span class="inf">Try to survive by using only the resources provided. Did we mention you're floating above lava? <p>Recommended Players: 4<br />
Author: <a href="http://www.minecraftforum.net/user/1021295-meh-own/" target="_new">Meh_Own</a></p></span>
</div>
<div class="right" style="position: relative">
<div style="width: 250px; height: 120; z-index: 6; position: absolute; top: 0px; height: 120px; left: 35px; cursor: pointer" class="righthover"></div>
<div style="background: url('maps/lavaseaofsurvival.jpg'); width:250px;height:150px;overfow:hidden;border:none;position: relative; z-index: 1">
<div style="background: url('img/vignette.png') no-repeat center center; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; z-index: 2"></div>
<div class="seeList" style="width: 100%; height: 100%; background: url(img/cbg.png) repeat; color: white; font-family: Georgia, 'Times New Roman'; font-size: 24px; margin: 0; padding: 0; font-style: italic; text-align: center; z-index: 1; display: none;"><div style="padding: 20px; padding-top: 40px;">See full list of maps...</div></div>
<img src="img/border.png" style="z-index: 3" />
<div class="directions" style="z-index: 5"></div>
</div>
</div>
</li>
[etc...]
-
极限
分支图。将大量主题混合到一张地图中 推荐玩家:3名
作者:
查看地图的完整列表。。。
-
生存的熔岩海
试着只使用提供的资源来生存。我们有没有提到你漂浮在熔岩之上 推荐玩家:4名
作者:
查看地图的完整列表。。。
[等等]
您的代码中可能有多个class=firstbox的元素,其中一些元素可能没有您试图访问的元素
在本例中,您可以尝试使用child()函数引用具有id映射框的元素的子元素,这可能会解决您的问题
在此特定示例中,没有li:n子项(2)。有一个li:n子项(0)和一个li:n子项(1)@eiu165“etc”表示还有更多。