这有可能,用CSS吗?
如果.div1不存在,请应用此规则:
.div2{
property: value;
}
Run Code Online (Sandbox Code Playgroud)
喜欢
<div class="div1">
...
</div>
<div class="div2">
<!-- it exists, so do nothing -->
</div>
Run Code Online (Sandbox Code Playgroud)
和
<div class="div2">
<!-- it doesn't exist, apply the css -->
</div>
Run Code Online (Sandbox Code Playgroud) var data = { url: $(this).attr('href'), selector: $(this) };
history.pushState(data, 'foo', $(this).attr('href'));
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我收到一个错误:
组件返回失败代码:0x8000ffff(NS_ERROR_UNEXPECTED)[nsIDOMHistory.pushState]
如果我将选择器更改为字符串,那么错误消失...但我需要jQuery对象,所以我可以在"popstate"事件上触发它点击:s