在Javascript中不禁用表中的整行
Not disabling Entire row in table in Javascript
本文关键字:Javascript 更新时间:2023-09-26
我写了一个基于某些条件禁用整行的函数,但对我来说,日期字段没有被禁用。请帮我改正一下。
从这里呼叫
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>
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 使用php或javascript从facebook相册URL中删除多余的部分
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 如何在JavaScript中将字符串转换为函数引用
- 模糊事件的Javascript测试
- Javascript更改图标
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 如何使用WCF服务和javascript表单post上传.doc文件
- javascript结合了数组和字典
- 这是什么 ==- javascript 运算符
- 从javascript创建一个列表
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Javascript:selenium Web驱动程序isDisplayed()不工作
- 如何通过ajax刷新JSF填充的javascript变量
- 如何在Javascript中将JSon对象转换为数组
- Javascript生成的表单未提交
- 使用javascript将动态表从一个html页面打印到另一个html页
- 通过javascript重定向html传递php变量