C# 使用 javascript 启用文本框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16520484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:13:18  来源:igfitidea点击:

Enabling text box using javascript

c#javascripthtmlasp.netcss

提问by Saurabh Palatkar

I've following textbox which is initially disabled:

我有以下最初被禁用的文本框

<input id="txtCustFName" name="txtRCustFName" type="text" required disabled="true"/>

on click on following anchor tag i m calling the js to enable the above text box: HTML:Enable

单击以下锚标记,我调用 js 以启用上述文本框: HTML:启用

JS:

JS:

EnableTxt()
{
    document.getElementById("txtCustFName").disabled = false;
}

But this code is not working. I am not able to enable text box.

但是这段代码不起作用。我无法启用文本框。

How can I do this?

我怎样才能做到这一点?

采纳答案by Altaf Sami

You can enable/disable using this:

您可以使用以下方法启用/禁用:

function EnableTxt() {
       document.getElementById( '<%=txtRCustFName.ClientID%>' ).disabled = 'false';
   }

回答by Samjongenelen

You should use the attribute of the textbox.

您应该使用文本框的属性。

jQuery:

jQuery:

($this.attr('disabled')) $this.removeAttr('disabled');

Please note that this is not supported in IE6

请注意,这在 IE6 中不受支持

回答by Kiren Siva

Try this:-

尝试这个:-

document.getElementById("txtCustFName").setAttribute("disabled", false);

回答by Aijaz Chauhan

you can do that by setting style using java script

你可以通过使用java脚本设置样式来做到这一点

for example:

例如:

document.getElementById("txtCustFName").setAttribute("style", "disabled:disabled"); 

回答by Anna.P

JavaScript

JavaScript

function myfunction(event) {
            alert('some anchor clicked');
            $('#txtCustFName').prop("disabled",false);
            return false;
      };
$(document).ready(function(){
          $('#myanchorid').click(myfunction);
          $('a.anchorclass').click(myfunction);
          $('#anchorlist > a').click(myfunction);
});

HTML

HTML

<html xmlns="http://www.w3.org/1999/xhtml" >
<script type="text/javascript" id="Script1" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript" id="myScript" src="myScript.js"></script>

<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a id="myanchorid" href="#">Click Me</a><br />
    <a class="anchorclass" href="#">Click Me</a><br />
<input id="txtCustFName" name="txtRCustFName" type="text" required disabled="true"/><br />
    <div id="anchorlist">
          <a href="#">Click Me</a>
          <a href="#">Click Me</a>
          <a href="#">Click Me</a>
    </div>
    </div>
    </form>
</body>
</html>

Try this....this will resolve your problem...

试试这个......这将解决你的问题......

回答by Ramakant Shukla

Try this:

尝试这个:

function EnableTxt() {
   $("#txtCustFName").prop("disabled", false);
}

Here "prop" is used for property/attribute of the tag.

这里“prop”用于标记的属性/属性。

回答by wale A

Removing the attribute worked allowed me edit the content of the textbox :

删除有效的属性允许我编辑文本框的内容:

document.getElementById("questionnaireText").removeAttribute("disabled");

To set the textbox to disableduse :

设置要disabled使用的文本框:

document.getElementById("questionnaireText").setAttribute("disabled", true);