function styledisplay(x,y)
{
var h=document.getElementsByTagName("tr");
for(var i=x; i<y; i++){
h[i].style.display="none";
}
}
我想在隐藏同时只读,该怎么写呢?
{
var h=document.getElementsByTagName("tr");
for(var i=x; i<y; i++){
h[i].style.display="none";
}
}
我想在隐藏同时只读,该怎么写呢?
<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>
或者干脆点 直接删掉这个dom
var h=document.getElementsByTagName("input");
for(var i=x; i<y; i++){
h[i].readonly="true";
}
$(this).attr("readOnly","false");//不管大写还是小写通通失效
只有this.readOnly=false;可以
<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>
哥们你试试吧, 刚开始还真吓我一跳..........