<table border="0" cellpadding="0" cellspacing="0" width="712" align="center">
                                                                                <% foreach (var item in Model)
                                                                                   { %>
                                                                                <tr height="26">
                                                                                    <td valign="middle" align="center" width="32" class="style3 TextBox3">
                                                                                        <%=Html.Encode(item.SendTaskId) %>
                                                                                    </td>                                                                                    
                                                                                    <td valign="middle" align="left" width="90" class="style3 TextBox3">
                                                                                        <div class="ProgressBarBorder">
                                                                                            <div id="Div_Pro" style="background-repeat: repeat-x; height: 9px; background-image: url(../../Content/Images/Progress1.jpg);"
                                                                                                onload='fun(<%= Html.Encode(item.Percentage)%>)'>
                                                                                            </div>
                                                                                        </div>
                                                                                    </td> 我想根据 item.percentage的值 来用js 改变div的宽度
 可是每次都没变 帮忙看看吧
 下面是js <script type="text/javascript">
        function fun(i) {
            if (i == 0) {
                document.getElementById("Div_Pro").style = "width:1px;";
            } else if(i>0)
            { document.getElementById("Div_Pro").style = "width:" + i + "px;"; }
        }
    </script>

解决方案 »

  1.   

    顺序走错了吧,别用onload,用jquery:$(document).ready,这个方法是在页面加载的最后执行的
      

  2.   


      看到上面的foreach没、?
     每行的值都不一样
    jquery:$(document).ready
     我没用过 所以也不知道他的特性 不知道是在页面佳作最后执行所有 还是什么
     谢谢
      

  3.   

    你的代码位置有问题,
     <% foreach (var item in Model)
    在解析的时候,是否会执行JS,这个我现在不太清楚,但是你应该换一个地方执行JS.比如在<% foreach (var item in Model) 结束之后。
      

  4.   

     在 foreach 结束之后   用什么事件获取item.Percentage的值?
      

  5.   


     <div id="Div_Pro" style="background-repeat: repeat-x; height: <%= Html.Encode(item.Percentage)%>px; background-image: url(../../Content/Images/Progress1.jpg);"> </div>