Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery progressbar随机图像宽度_Javascript_Jquery_Css - Fatal编程技术网

Javascript Jquery progressbar随机图像宽度

Javascript Jquery progressbar随机图像宽度,javascript,jquery,css,Javascript,Jquery,Css,我真的不知道我做错了什么。我想将图像的宽度更改为0-100%的随机数。有人能告诉我我做错了什么吗 function progress(){ $("body").append("<div class='main_div'></div>"); var x = Math.floor(Math.random() * 10) + 1; var x = 5; for(var i = 0; i < x; i++){ $(

我真的不知道我做错了什么。我想将图像的宽度更改为0-100%的随机数。有人能告诉我我做错了什么吗

function progress(){


    $("body").append("<div class='main_div'></div>");

    var x = Math.floor(Math.random() * 10) + 1;
    var x = 5;

    for(var i = 0; i < x; i++){


        $(".main_div").append("<div class='statusbar'></div>");
        $(".statusbar:nth-child(" + x + ")").append("<img src='project_status.gif'>");

        var c = Math.floor(Math.random() * 100) + 1;
        $(".statusbar:nth-child(" + x + ") img").css({ "width", "(" + c +")%" });

    }

}
函数进度(){
$(“正文”)。追加(“”);
var x=数学地板(数学随机()*10)+1;
var x=5;
对于(变量i=0;i
您的
Math.floor()函数中有错误。
函数:而不是

Math.floor(Math.random() * 10) + 1;
应该是

Math.floor((Math.random() * 10) + 1));
Math.floor
括号内使用+1


我不知道这是否有用,但我之前在这里生成了一个随机大小的进度条:

问题在于此语句:

$(".statusbar:nth-child(" + x + ") img").css({ "width", "(" + c +")%" });
您应该阅读JQuery
.css()
函数:

但是当您将
.css()
函数与
{}
括号一起使用时,语法与css本身相同

因此,对于您的陈述,正确的方式是:

.css({ width : c +"%" })
或者,如果您想保持原来的状态,只需删除
{}
括号:

.css( "width", c +"%")

我也很确定你不需要在
()

中包装
c
,谢谢你的回答。我解决了这个问题。但是这里的问题是$(“.statusbar:nth child(“+x+”).img”).css({“width”,“(“+c+”)%”%”});仍然开放