如果一个类有样式,那么跳过它的Javascript循环

时间:2018-03-04 18:38:33

标签: javascript loops if-statement

我在javascript循环中遇到了问题。 我正在创建一个chrome扩展,甚至我已经实现了它。首先,我想要有一个差距,我做了那个,但现在我有另一个问题,它让我发疯。 我有一些类我想告诉我的循环如果一个类在代码中有样式然后从循环中跳过它并转到另一个。 我的代码是。 我想要时间循环,我希望它跳过那些有风格的类。 或者如果它不可能则是,我希望它跳过那些具有area-pressed = true的类。 这是我的代码。 :D



function nothing(){

var inputs= document.getElementsByClassName('checking');
var get= document.getElementsByClassName('nothing').style;
function doSetTimeout(i) {
    setTimeout(function() { inputs[i].click(); }, i*1000);
}
for (var i=0; i<inputs.length;i++)
if ( get == null) {
       doSetTimeout(i);
    }
}
&#13;
     <button onclick="nothing()"> Hey </button>  
    <a href="#" class="checking" area-pressed="false"> Nothing </a>
    <a href="1" class="checking" style="noting"> Nothing </a>
    <a href="3" class="checking"  style=""> Nothing </a>
   <a href="4" class="checking" area-pressed="true"> Nothing </a>
    <a href="5" class="checking" area-pressed="false"> Nothing </a> 
  
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

在for循环中尝试if (inputs[i].style.<your property> === "<your value>") continue再做其他事情

例如:if (inputs[i].style.background === "red") continue

答案 1 :(得分:0)

您需要使用import { colors } from "./colors" import { fonts } from "./fonts" import { StyleSheet } from "react-native" export default StyleSheet.create({ container: { height: 10, flex: 1, padding: 30, flexDirection: "column", justifyContent: "space-around" }, header: { justifyContent: "space-between", borderColor: colors.grape, borderRadius: 2, }, carRegNr: { fontWeight: "bold", color: colors.black, fontSize: 25, }, groupTight: { flexDirection: "column", justifyContent: "flex-start" }, insuranceName: { color: colors.black, fontSize: 23 }, flexRow: { flexDirection: "row", justifyContent: "space-between", }, flexColumn: { width: "100%", flexDirection: "column", }, nextStepsText: { color: colors.black, fontSize: 25, fontWeight: "bold", }, nextStepsDetails: { color: colors.black, fontSize: 20, }, bold: { color: colors.black, fontWeight: "bold", }, cont: { margin: 5, padding: 3, }, claimNrText: { color: colors.black, margin: 0, padding: 0, fontSize: 30, }, claimNr: { fontSize: 26, } }) 获取循环中每个元素的样式,然后检查它是否已设置。

inputs[i].style