我正在尝试使用JavaScript列出幻灯片中的img元素,这是容器中的所有子元素。在那个容器中,我还有两个用于导航箭头的div。它们还包含一个子img元素。
如何使用纯JavaScript列出第一组img元素而不是导航箭头?
<div id='imgContain'>
<?php
$path = "./resSlide";
$all_files = scandir($path);
$how_many = count($all_files);
for ($i=2; $i<$how_many;$i++) {
$num=$i-1;
echo "<img src=\"./resSlide/$all_files[$i]\" id= \"$num\" class= \"slideImg2\"/>";
}
?>
<div id='imgPosbar'>
<div id='imgPosbarIn'></div>
</div>
<div id='imgPosLeftBut' onclick='LeftClick();'>
<img class='imgBut' src="leftarrow.png" alt='Sorry'>
</div>
<div id='imgPosRightBut' onclick='RightClick();'>
<img class='imgBut' src='rightarrow.png' alt='Sorry'>
</div>
</div>
答案 0 :(得分:1)
这将选择img
#imgContain
,它是var elems = document.querySelectorAll('#imgContain > img');
for (var i = 0; i < elems.length; i++) {
// do something with each img
var el = elems[i];
}
的直接子项
public func presentationControllerForPresentedViewController(presented: UIViewController?, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
let viewController = BaseViewController()
if (viewController.(somePropertyInViewController)) {
return BWOverlayPresentationController(presentedViewController: presented, presentingViewController: presenting)
}
else {
return BWSettingsPresentationController(presentedViewController: presented, presentingViewController: presenting)
}