function styledisplay(x,y)
{
var h=document.getElementsByTagName("tr");
for(var i=x; i<y; i++){
h[i].style.display="none";
}
}
我想在隐藏同时只读,该怎么写呢?

解决方案 »

  1.   

    <!DOCTYPE HTML>
    <html>
    <head>
        <title>无标题文档</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            function styledisplay(x, y) {
                $("#tableList tr").each(function (index) {
                    if (index >= x && index <= y) {
                        //$(this).hide();       //此处是为了测试只读而注释了, 如你要实际使用, 去掉即注释可
                        $(this).find("input").attr("readonly",true);
                    }
                });
            }
        </script>
    </head>
    <body>
        <input type="button" value="Test" onclick="styledisplay(0, 2)" />
        <table id="tableList" style="width: 100%;">
            <tr><td><input type="text" value="1" /></td></tr>
            <tr><td><input type="text" value="2" /></td></tr>
            <tr><td><input type="text" value="3" /></td></tr>
            <tr><td><input type="text" value="4" /></td></tr>
        </table>
    </body>
    </html>
      

  2.   

    readonly请大写o readOnly另外你设了只读,你的验证照样会走.看一下是根据什么获取到这个dom去验证了 把这个标识给改掉
    或者干脆点 直接删掉这个dom
      

  3.   

    你是要让表单只读,那么可以加上下面这段代码,把本页的所有表单都设为只读
      var h=document.getElementsByTagName("input");
      for(var i=x; i<y; i++){
          h[i].readonly="true";
      }
      

  4.   

    你用VS2010试一下, 代码提示就是readonly了. 
      

  5.   

    这个东西如果为了安全的话都是在后台验证的,前台就display就可以了
      

  6.   

    敢问你有没有试过设了只读之后再启用
    $(this).attr("readOnly","false");//不管大写还是小写通通失效
    只有this.readOnly=false;可以
      

  7.   

    <!DOCTYPE HTML>
    <html>
    <head>
        <title>无标题文档</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            function styledisplay(x, y) {
                $("#tableList tr").each(function (index) {
                    if (index >= x && index <= y) {
                        //$(this).hide();       //此处是为了测试只读而注释了, 如你要实际使用, 去掉即注释可
                        $(this).find("input").attr("readonly", true);
                    }
                });
            }
            function setAllNotReadOnly() {
                $("input").attr("readonly",false);
            }
        </script>
    </head>
    <body>
        <input type="button" value="1-3只读" onclick="styledisplay(0, 2)" /><br />
        <input type="button" value="全部可读写" onclick="setAllNotReadOnly()" />
        <table id="tableList" style="width: 100%;">
            <tr><td><input type="text" value="1" /></td></tr>
            <tr><td><input type="text" value="2" /></td></tr>
            <tr><td><input type="text" value="3" /></td></tr>
            <tr><td><input type="text" value="4" /></td></tr>
        </table>
    </body>
    </html>
    哥们你试试吧, 刚开始还真吓我一跳..........