简体   繁体   English

使用javascript无法禁用文本框。禁用后立即启用。 谁能给我解决方法?

[英]Using javascript Not able to disable textbox.It Immediatly enable after disabled. Can anyone give me solution?

I have One simple registration Form which is developed in C#.Net. 我有一个用C#.Net开发的简单注册表格。 This form also contain one Grid view which display data from database.In this,I want to disable Insert button when i select particular raw data. 此表单还包含一个显示数据库中数据的网格视图。在此,我要在选择特定原始数据时禁用“插入”按钮。 and i had develop this code in jquery. 我已经在jQuery中开发了此代码。 I used below code. 我用下面的代码。

function DoStuff(lnk) {
        debugger;
        var grid = document.getElementById('GridView1');
        var cell, row, rowIndex, cellIndex;
        cell = lnk.parentNode;
        row = cell.parentNode;
        rowIndex = row.rowIndex;
        cellIndex = cell.cellIndex;

        var rowId = grid.rows[rowIndex].cells[0].textContent;
        var rowname = grid.rows[rowIndex].cells[1].textContent;
        var rowcontact = grid.rows[rowIndex].cells[2].innerHTML;
        var rowaddress = grid.rows[rowIndex].cells[3].innerHTML;
        var rowemail = grid.rows[rowIndex].cells[4].innerHTML;
        var Id = document.getElementById('txt_Id');
        var name = document.getElementById('txt_Name');
        var contact = document.getElementById('txt_PhoneNumber');
        var address = document.getElementById('txt_Address');
        var email = document.getElementById('txt_EmailId');


        Id.value = rowId;
        name.value = rowname;
        contact.value = rowcontact;
        address.value = rowaddress;
        email.value = rowemail;
       document.getElementById('Button1').disabled = true;
                };

But when i run that page it becomes disable and immediately enable automatically.....:( Can anyone give me solution ??? 但是,当我运行该页面时,它将变为禁用状态并立即自动启用..... :(谁能给我解决方案?

You have to call this function after form is completely loaded. 表单完全加载后,必须调用此函数。 Use below code to make it that happen if you are using jQuery. 如果使用的是jQuery,请使用下面的代码来实现。

$( document ).ready(function() {
    DoStuff(lnk);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM