开发者

disable (grey out) the previous row(s)

开发者 https://www.devze.com 2023-01-06 00:56 出处:网络
I would like to grey out (disable) the previous row(s), every time I add a new one. Right now I could only disable the first one. Many thanks in advance. Following is what I could do so far:

I would like to grey out (disable) the previous row(s), every time I add a new one. Right now I could only disable the first one. Many thanks in advance. Following is what I could do so far:

<head>
<SCRIPTTYPE="text/javascript">
varcount="1";
functionaddRow(in_tbl_name){
vartbody=document.getElementById(in_tbl_name).getElementsByTagName("TBODY")[0];
varrow=document.createElement("TR"开发者_如何学JAVA);
vartd1=document.createElement("TD")
varstrHtml1="<SELECTNAME=\"sel_1\"><optionvalue=\"a\">a<optionvalue=\"b\">b<optionvalue=\"c\">c<optionvalue=\"d\">d</SELECT>";
td1.innerHTML=strHtml1.replace(/!count!/g,count);
row.appendChild(td1);
count=parseInt(count)+1;
tbody.appendChild(row);
myform.sel1.disabled=true;
}
functiondelRow(){
varcurrent=window.event.srcElement;
while((current=current.parentElement)&&current.tagName!="TR");
current.parentElement.removeChild(current);
}
</SCRIPT>
</head>
<body>
<div>
<formaction="#"method="POST"name="myform">
<divstyle="">
<TABLEID="mytable"name="mytable"border="1"STYLE="border-width:1pxorangedashed;background-color:#F0E68C;table-row-width:2;">
<TR>
<TD>
<selectsize="1"name="sel1">
<optionvalue="a">a</option>
<optionvalue="b">b</option>
<optionvalue="c">c</option>
<optionvalue="d">d</option>
</select>
</TD>
</TR>
</TABLE>
</div>
<div>
<INPUTTYPE="Button"onClick="addRow('mytable')"VALUE="Add">
</div>
</form>
</div>
</body>


Apply a CSS on that row. Row's don't have any concept of being "disabled" - they are simply rows. How they appear is driven by CSS.

Update: If you want to disable the form inputs in the row, simply find that element in the previous row, using e.g. jQuery, or manually (using DOM methods) if the DOM path of the SELECT is always the same.

0

精彩评论

暂无评论...
验证码 换一张
取 消