我的tbody
里面有href
/ input
type
text
/ etc
我有一个代码来获取tbody
的所有元素,但是如何禁用它。
我的身体
<tbody id="FamilyHistory_3">
<tr>
<td class="tablecell">
<a id="FamilyHistory_3" name="316098" value="316098" onclick="javascript:save('FamilyHistory_3','test');" href="#">
<img style="border-style: none" src="../images/v10/arrow_doc.png">
</a> test
</td>
</tr>
<tr>
<td>
<table>
<tbody>
<tr>
<td></td>
<td class="tablecell">
<input type="checkbox" value="Yes" name="10627_316098">Yes
<input type="checkbox" checked="" value="No" name="10627_316098">No
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td height="2px"></td>
</tr>
</tbody>
以下是获取tbody
function save(inputID,category){
var content= document.querySelectorAll('#tbodyID');
for(var i=0; i<content.length; i++){
// how to disable all the elements inside it
}
}
答案 0 :(得分:4)
document.querySelector('#tbodyID input').disabled = true;
你不需要jQuery。
不止一个:
var l = document.querySelectorAll('#tbodyID input');
for (i = 0;i<l.length;i++)
{
l[i].disabled = true;
}
答案 1 :(得分:2)
没有必要循环,jquery可以使用选择器来处理元素组。
使用Jquery选择器和prop函数为每个选项添加disabled="disabled"
。
您还可以使用comma separated list
选择多个项目$('#tbodyID input, #tbodyID select, ....').prop('disabled', true);
禁用a
标记不会阻止它被点击。可能会更好hide()
这些。
$('#tbodyID a').hide();
答案 2 :(得分:2)
您可能需要指定要禁用的所有元素的类型。如果你有jQuery,你可以这样做:
$('#tbodyID').find('a, input').prop('disabled', true);
<强>解释强>
$('#tbodyID')
:选择ID为tbodyID
find('a, input')
:查找其中的所有a
和input
元素prop('disabled', true)
:设置上一个命令返回的每个元素的disabled
属性答案 3 :(得分:0)
根据你的回答,我最终使用下面的代码完成了我的任务。我知道你们已经有人回答但是我也在发布我的回答,只有一些补充。
停用输入
$('[id='+inputID+']').find('input').attr('disabled', true);
id of tbody
禁用点击但可点击的手牌会在那里,但不会向服务器提交任何请求
$('[id='+inputID+']').attr('onclick','').unbind('click');
锚标记的ID
谢谢,
PISE