Twitter bootstrap 3 洗牌

Twitter bootstrap 3 洗牌,twitter-bootstrap-3,Twitter Bootstrap 3,我已经创建了一个包含2行7列的表。在第一行中,每个单元格都将使用不同的颜色。在第二行中,我创建了一个文本框。现在我希望我的第一行颜色可以使用jquery或javascript进行混洗。也就是说,颜色应该放在不同的单元格中。 这是我的颜色表代码 <div class="form-group" > <label class="control-label col-sm-2" for="pwd" style="color:#FFFFFF" > Color Password:<

我已经创建了一个包含2行7列的表。在第一行中,每个单元格都将使用不同的颜色。在第二行中,我创建了一个文本框。现在我希望我的第一行颜色可以使用jquery或javascript进行混洗。也就是说,颜色应该放在不同的单元格中。 这是我的颜色表代码

<div class="form-group" >
<label class="control-label col-sm-2" for="pwd" style="color:#FFFFFF" > Color Password:</label>
<div class="col-sm-5">
<table  border="5px" width="300px" height="50px" align="center">
<tr>
<label><td bgcolor="blue" height="25px" ></td></label>
<label><td bgcolor="red" height="25px" ></td></label>

<label><td bgcolor="green" height="25px" ></td></label>
<label><td bgcolor="yellow" height="25px" ></td></label>

<label><td bgcolor="orange" height="25px" ></td></label>
<label><td bgcolor="black" height="25px" ></td></label>

<label><td bgcolor="pink" height="25px"></td></label>
<label><td bgcolor="brown" height="25px"></td></label>
</tr>
<tr>
<td> <input type="text" size="4" name="blue"></td>
<td> <input type="text" size="4" name="red"></td>
<td> <input type="text" size="4" name="green"></td>
<td> <input type="text" size="4" name="yellow"></td>
<td> <input type="text" size="4" name="orange"></td>
<td> <input type="text" size="4" name="pink"></td>
<td> <input type="text" size="4" name="brown"></td>

</tr>
</table>

</div></div>
这是我的输出:
现在,我希望所有这些颜色都被洗牌。有人能帮我吗。

你可以使用jQuery像那样刷背景色

var colorCells = $('#colors > td');
$.each(colorCells, function(idx){
  $(colorCells[idx]).css("background-color", '#'+Math.random().toString(16).slice(-6));
})
或者不使用jQuery:

var colorCells = document.getElementById('colors').getElementsByTagName('td');
for(var i = 0; i < colorCells.length; i++){
    colorCells[i].style.backgroundColor = '#'+Math.random().toString(16).slice(-6);
}
如果这就是您想要使用的所有JavaScript代码,我建议不要使用纯JavaScript版本

编辑:

如果您只想使用一组固定的颜色:

var colorCells = document.getElementById('colors').getElementsByTagName('td');
var colors = ["blue","red","green","yellow","orange","pink","brown","black"];
for(var i = 0; i < colorCells.length; i++){
    colorCells[i].style.backgroundColor = colors.splice(Math.random() * (colors.length - 0) + 0,1);
}

你的jquery或javascript在哪里?我不熟悉jquery。所以我没有用它尝试任何代码。我想让你告诉我,在我的代码中,有没有办法洗牌颜色以及如何洗牌???谢谢,但如果你查看我的输出,我只使用了7种颜色,我只想洗牌这7种颜色。比如说,如果蓝色占据第一个单元格,洗牌后,它可能会占据第三位等。我已经确定了我的颜色。它们是蓝色、红色、绿色、黄色、橙色、粉色、棕色、黑色。我只想把这些颜色混在一起。看看我上面编辑过的答案,这应该很好:注意你使用的颜色至少必须是表格单元格的数量。没问题,请考虑把我的答案标记为正确:你能告诉我如何在洗牌后获得每个单元格的颜色名称吗?Patrick Rath