使用jQuery或普通JS
例如:
<div class="mydivclass">Some Text1</div>
<div class="am I beside mydivclass ???">Some Text2</div>
答案 0 :(得分:3)
使用“+”运算符。
这是一个例子,你可以看到只有第二个是绿色,因为它直接位于第一个div之后。
.first, .second, .third {
width: 100px;
height: 20px;
background-color: red;
}
.first + .second {
background-color: green;
}
.first + .third {
background-color: green;
}
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
答案 1 :(得分:0)
邻居可以在相关元素之前或之后:
<div class="mydivclass">Some Text1</div>
<div class="am-I-beside-mydivclass">Some Text2</div>
Node.prototype.getClasses = function() {
return this.className ? this.className.split(" ") : "";
};
Node.prototype.hasClass = function(c) {
return this.getClasses().indexOf(c) >= 0;
};
function isNeighbour(element, cn) {
var siblings = element.parentNode.children;
var index = Array.prototype.indexOf.call(element.parentNode.children, element);
if (index === -1) return false;
return (index >= 0) &&
(((index > 0) && (siblings[index - 1].hasClass(cn))) ||
((index < siblings.length - 1) && (siblings[index + 1].hasClass(cn)))
)
}
getClasses
返回任何Node
,hasClass
的类,检查Node
是否有class
和isNeighbour
检查class
是否function isNeighbour(element, cn) {
return (element.prev().hasClass(cn) || element.next().hasClass(cn));
}
1}} name匹配元素的上一个或下一个兄弟。
import pandas as pd
import numpy as np
from scipy.optimize import minimize
import matplotlib.pyplot as plt
np.random.seed(1234)
# Reproducible data sample
def returns(rows, names):
''' Function to create data sample with random returns
Parameters
==========
rows : number of rows in the dataframe
names: list of names to represent assets
Example
=======
>>> returns(rows = 2, names = ['A', 'B'])
A B
2017-01-01 0.0027 0.0075
2017-01-02 -0.0050 -0.0024
'''
listVars= names
rng = pd.date_range('1/1/2017', periods=rows, freq='D')
df_temp = pd.DataFrame(np.random.randint(-100,100,size=(rows, len(listVars))), columns=listVars)
df_temp = df_temp.set_index(rng)
df_temp = df_temp / 10000
return df_temp
这段代码很容易理解,但它有jQuery作为依赖。