如何使用 JQuery 函数启用表单字段



我正在设置一个包含 11 行 11 列的表单。通常应该禁用表单行和列,但是当我单击名为"编辑"的按钮时,它应该启用所有表单字段。如果有人在这种情况下帮助我,那就太好了。提前致谢

我的编辑按钮 :

<table class="auto-style15" style="width: 100%; height: 100%;">
<tr>
    <td class="auto-style11" rowspan="2" style="width: 70px"><strong>Operation No</strong></td>
    <td class="auto-style22" rowspan="2" style="width: 156px"><strong>Fixture No</strong></td>
    <td class="auto-style22" rowspan="2" style="width: 55px"><strong>Rev</strong></td>
    <td class="auto-style22" colspan="5"><strong>Status</strong></td>
    <td class="auto-style22" rowspan="2" style="width: 59px"><strong>Storage</strong></td>
    <td class="auto-style22" rowspan="2" style="width: 42px"><strong>ChecksTo Be<br />
    Done</strong></td>
    <td class="auto-style22" rowspan="2" style="width: 154px"><strong>Remarks</strong></td>
</tr>
<tr>
    <td class="auto-style7" style="width: 70px; height: 25px">
    <input name="oprno1" type="text" style="width: 70px" /></td>
    <td class="auto-style7" style="height: 25px; width: 156px">
    <input name="fixno1" style="width: 150px" type="text" /></td>
    <td class="auto-style7" style="height: 25px; width: 55px">
    <input name="rev1" style="width: 50px" type="text" /></td>
<input name="Button1" type="button" value="EDIT" disabled class="auto-style12" />

如果我

理解正确,您想要的是启用或禁用表单上的控件......这个问题在这里已经辩论过,并得到了回答。请看看它是否是你需要的。

http://jsfiddle.net/vGc5P/1/

$().ready(function() {

$('#clicker').click(function() {
    $('input').each(function() {
        if ($(this).attr('disabled')) {
            $(this).removeAttr('disabled');
        }
        else {
            $(this).attr({
                'disabled': 'disabled'
            });
        }
    });
});

});

问题启用/禁用输入元素的脚本?

jQuery 1.6+

您可以通过设置 .prop('disabled', false); 来启用这些字段。

$('input').prop('disabled', false);

jQuery 1.5 及更低

版本
$('input').removeAttr('disabled');

函数

$(document).on('click', '.edit', function () {
    $('input').prop('disabled', false);
});

您可以定位表中的inputtextarea字段,并为其指定类或 ID。

$('table#edit input, table#edit textarea').prop('disabled', false);

演示

<strong>
<input name="Button1" type="button" value="EDIT" disabled class="auto-style12" />
<script>
$('.auto-style12').click(function(){
    $('#textfield-id').removeAttr('disabled');
})
</script>

使用 jQuery

最新更新