gpt4 book ai didi

javascript - 不禁用 Javascript 中表中的整行

转载 作者:行者123 更新时间:2023-12-03 12:27:32 24 4
gpt4 key购买 nike

我编写了一个函数,可以根据某些条件禁用整行,但对我来说,日期字段没有被禁用。请帮我纠正它。

从这里调用

var rowCount = document.getElementById("BLK_CLVWS_COMPSCH").tBodies[0].rows.length;
if(rowCount > 0)
{
for(var i=0; i<rowCount; i++)
{
if ((document.getElementById("BLK_CLVWS_COMPSCH").tBodies[0].rows[i].cells[20].getElementsByTagName("INPUT")[0].value)=='N')
fnDisablesch(i);
}
}

功能是

function fnDisablesch(z)
{
var tblEventRef = document.getElementById("BLK_CLVWS_COMPSCH").tBodies[0];
var rowRef = tblEventRef.rows;


rowRef[z].cells[0].getElementsByTagName("INPUT")[0].disabled = true;
rowRef[z].cells[1].getElementsByTagName("SELECT")[0].disabled = true;
rowRef[z].cells[2].getElementsByTagName("SELECT")[0].disabled = true;
rowRef[z].cells[3].getElementsByTagName("INPUT")[0].disabled = true;
rowRef[z].cells[3].getElementsByTagName("INPUT")[0].nextSibling.style.visibility="hidden";
rowRef[z].cells[4].getElementsByTagName("INPUT")[0].disabled = true;
rowRef[z].cells[5].getElementsByTagName("INPUT")[0].nextSibling.disabled = true;
rowRef[z].cells[6].getElementsByTagName("INPUT")[0].nextSibling.disabled = true;
rowRef[z].cells[7].getElementsByTagName("SELECT")[0].disabled = true;
rowRef[z].cells[8].getElementsByTagName("INPUT")[0].nextSibling.disabled = true;
rowRef[z].cells[9].getElementsByTagName("INPUT")[0].disabled = true;
rowRef[z].cells[10].getElementsByTagName("INPUT")[0].nextSibling.disabled = true;
rowRef[z].cells[11].getElementsByTagName("INPUT")[0].nextSibling.disabled = true;
rowRef[z].cells[12].getElementsByTagName("INPUT")[0].nextSibling.disabled = true;
rowRef[z].cells[13].getElementsByTagName("INPUT")[0].nextSibling.disabled = true;
rowRef[z].cells[14].getElementsByTagName("INPUT")[0].nextSibling.disabled = true;
rowRef[z].cells[15].getElementsByTagName("SELECT")[0].disabled = true;
rowRef[z].cells[16].getElementsByTagName("SELECT")[0].disabled = true;
rowRef[z].cells[17].getElementsByTagName("INPUT")[0].disabled = true;
rowRef[z].cells[18].getElementsByTagName("INPUT")[0].disabled = true;

return true;
}

最佳答案

也许这能有所帮助?

这会启用/禁用行本身内的所有内容,生成一些假数据来使用

<html>
<head>
<title>Disable Row</title>
<script type="text/javascript">
function setState(element, state) {
element.disabled = state;
var children = element.children, i;
if (children === null || children.length === 0) {
return;
}
for (i = 0; i < children.length; i++) {
setState(children[i], state);
}
}

function setRowState(tableid, index, state) {
var table = document.getElementById(tableid);
if (!table) {
return;
}
var row = table.rows[index];
if (!row) {
return;
}
setState(row, state);
}

function generateData(tableid) {
var table = document.getElementById(tableid);
if (!table) {
return;
}
for (var i = 0; i < 40; i++) {
var row = document.createElement(i === 0 ? 'th' : 'tr');
for (var j = 0; j < 10; j++) {
var cell = document.createElement('td');
if (i == 0) {
cell.innerHTML = 'header ' + j;
row.appendChild(cell);
continue;
}
var input = document.createElement('input');
input.type = 'text';
if (j % 3 === 0) {
input.type = 'date';
}
if (j % 4 === 0) {
input.type = 'button';
}
cell.appendChild(input);
row.appendChild(cell);
}
table.appendChild(row);
}
}

function activate(tableid, text) {
var el = document.getElementById(text).value;
setRowState(tableid, parseInt(el), false);
}

function deactivate(tableid, text) {
var el = document.getElementById(text).value;
setRowState(tableid, parseInt(el), true);
}
</script>
</head>
<body onload="javascript:generateData('fakedata');">
<input id="rowToUpdate" value="5" /><button id="activate" onclick="javascript:activate('fakedata', 'rowToUpdate');">Activate</button><button id="deactivate" onclick="javascript:deactivate('fakedata', 'rowToUpdate');">Deactivate</button>
<table id="fakedata">
</table>
</body>
</html>

关于javascript - 不禁用 Javascript 中表中的整行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24115641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com