我有一种情况,我需要根据POP的“打开器窗口”是否定义了样式类在POPUP上应用样式。
<html>
<body class="myClass">
<input type="button" onClick="Open('xyz.html')"/>
</body>
</html>
现在在
xyz.html
上,我想要一个CSS选择器,它可以根据parent.html
是否具有class="myClass"
来切换某些样式。没有Jquery,有可能吗?
如果没有:我有什么替代方案,包括Jquery和Javascript?
请注意:
parent.html
正在打开xyz.html
,它们都是单独的窗口。 最佳答案
您不需要使用jQuery进行检查。您可以使用简单的CSS。检查下面的代码。在这里,如果container
具有类my-class
。 background-color
的属性将应用于弹出窗口。否则,不会。检查代码,并尝试在my-class
中带有和不带有container
的情况下使用相同的代码。
$('button').on('click', function() {
$('.popup').toggleClass('active')
})
.popup {
padding: 10px;
border: 1px solid #ddd;
opacity: 0;
transition: all 0.8s ease;
}
.popup.active {
opacity: 1;
}
.container.my-class .popup {
background-color: red;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container my-class">
<button>Click</button>
<div class="popup"> HAI </div>
</div>
关于javascript - 从弹出窗口中选择父实体,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46068508/