嘿朋友任何人请帮我解决这个问题。在这个javascript代码中我从控制器获取2个数组ID数组和百分比数组并将它们转换为javascript数组现在我想要动态更改元素的css属性但我需要成功。如果有人找到此代码中的错误请告诉我
@section javascript{
<script type="text/javascript">
$(document).ready(function() {
@{
string data = "";
int length = ViewBag.length;
}
var percent = new Array();
@for (int j = 0; j < length; j++)
{
data += "percent[" + j + "]=\"" + ViewBag.percentage[j] + "\";";
}
@MvcHtmlString.Create(data);
var ids = new Array();
@for (int i = 0; i < length; i++)
{
data += "ids[" + i + "]=\"" + ViewBag.IDs[i] + "\";";
}
@MvcHtmlString.Create(data);
//get current date day for javascript
var date = new Date();
var day = date.getDay();
var dayper = (day/30)*100;
//**************************************************************//
//Remaining amount in percentage variable as percent[i] is spend//
//amount percentage so subtracting spend percentage from 100 wil//
// return remaing amount percentage //
//**************************************************************//
var rA;
var per;
var id;
for(var k = 0;k<ids.length;k++)
{
per = percent[k];
id = ids[k];
document.getElementById(id).style.width = parseInt(per)+"%";
rA = 100 - parseInt(percent[k]);
if(rA - dayper > 40)
{
document.getElementById(id).style.background = "red";
}
else if((rA - dayper)>20 && (rA - dayper) < 40)
{
document.getElementById(id).style.background = "yellow";
}
else
document.getElementById(id).style.background = "green";
}
});
</script>