Javascript Css顺序属性没有';当Jquery设置时不更新
当元素在dom上以这种方式呈现后更新其order属性时,html元素无法重新排序Javascript Css顺序属性没有';当Jquery设置时不更新,javascript,jquery,css,Javascript,Jquery,Css,当元素在dom上以这种方式呈现后更新其order属性时,html元素无法重新排序 $(".test").css('order', '0'); 这是一个已知的问题吗 编辑:是,容器具有以下css属性: display: flex; flex-direction: column; overflow-y: overlay; overflow-x: hidden; position: relative; 编辑:小提琴中显示的错误 我的代码: $(".update").on("click", func
$(".test").css('order', '0');
这是一个已知的问题吗
编辑:是,容器具有以下css属性:
display: flex;
flex-direction: column;
overflow-y: overlay;
overflow-x: hidden;
position: relative;
编辑:小提琴中显示的错误
我的代码:
$(".update").on("click", function() {
for (var i = 0; i < $(".child").length; i++) {
$(".child").css("order", Math.floor(Math.random * 100));
}
});
$(.update”)。在(“单击”,函数(){
对于(变量i=0;i<$(“.child”).length;i++){
$(“.child”).css(“order”,Math.floor(Math.random*100));
}
});
您的代码有两个问题(从您的小提琴上)
Math.random
是一个函数,因此需要执行Math.random()
:eq(index)
选择器进行此操作$(.update”)。在(“单击”,函数(){
对于(变量i=0;i<$(“.child”).length;i++){
var order=Math.floor(Math.random()*100);
$(“.child:eq(“+i+”)).css(“order”,order);
}
});
旁注: 最好使用jquery的
。每个循环而不是for循环,这样会减少查询
然后在循环内部,您可以执行this.style.order=Math.floor(Math.random()*100)代码>您确定它是用flex css包装的吗?当我刚测试它时,它对我起作用了。你在用flexbox吗?这里需要一些上下文。@isherwood是的,请选中编辑。@HHHome您可以在代码段中显示示例代码吗?@HHHome您提供了一个提琴。编辑只是在你的问题中加入了相同的代码。所以我不明白这场战争的目的是什么。您提供了此代码。如果您被误解,并且得到的答案确实回答了您的问题,但不是您想要的,请打开一个新问题,链接到此问题,并准确解释您需要的不同之处。请在问题正文中包括代码示例和解释,以及任何相关链接,如JSFIDLLES。
$(".update").on("click", function() {
for (var i = 0; i < $(".child").length; i++) {
var order = Math.floor(Math.random() * 100);
$(".child:eq(" + i + ")").css("order", order);
}
});