开发者

Disable table in javascript

开发者 https://www.devze.com 2023-01-03 04:36 出处:网络
I have many cont开发者_C百科rols in table and I want to disable all the controls using JavaScript upon clicking of some checkbox.

I have many cont开发者_C百科rols in table and I want to disable all the controls using JavaScript upon clicking of some checkbox.

I have google and found that we can't disable table instead all controls through loop. Please suggest me, what is better idea

Thanks


Here's a simple script to do this.

var table = document.getElementById('yourTableId');
var inputs = table.getElementsByTagName('INPUT');
var links = table.getElementsByTagName('A');

for (var i = 0; i < inputs.length; i++) {
    inputs[i].disabled = true;
}

for (var i = 0; i < links.length; i++) {
    // There are better ways to disable links, but 
    // this is the shortest code to do it
    links[i].onclick = 'return false;';
}

This should run very efficiently, though it won't change the style of the table very much. Maksim's answer has a good solution for making the table look disabled.


You can check this solution, but its require Jquery. Disabling controls within a table - JQuery/Javascript

0

精彩评论

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