问题描述
我有一个asp.net按钮,默认情况下被禁用。我有一个多行模式的文本框。如果文本框为空,则按钮应保持禁用状态,如果其中有文本,则将启用按钮。以下是我的javascript代码。
< script>
函数SetButtonStatus(sender,target){
debugger
var first = document.getElementById('<%= txtMain.ClientID%>');
if(sender.value.length> = 1&& first.value.length> = 1)
document.getElementById(target ).disabled = false;
else
document.getElementById(target).disabled = true;
}
< / script>
这是我的文本框。
< asp:TextBox runat =serverID =txtMainRows =200TextMode =MultiLine
Columns =150 onkeyup =SetButtonStatus(this,'btnsubmit')>< / asp:TextBox>< br />
现在,如果我选择TextMode =MultiLine。我的javascript函数不是woprk。如果我删除多线模式,它的工作原理很完美。我尝试使用textarea而不是文本框但它没有用。我也尝试使用html按钮而不是asp.net按钮,但它无法正常工作。
任何帮助将不胜感激。谢谢。
I have an asp.net button which is disabled by default. I have a textbox with multiline mode. If textbox is empty then button should remainn disabled and if there is text in it, then button will be enabled. Below is my javascript code.
<script> function SetButtonStatus(sender, target) { debugger var first = document.getElementById('<%=txtMain.ClientID %>'); if (sender.value.length >= 1 && first.value.length >= 1) document.getElementById(target).disabled = false; else document.getElementById(target).disabled = true; } </script>
This is my textbox.
<asp:TextBox runat="server" ID="txtMain" Rows="200" TextMode="MultiLine" Columns="150" onkeyup="SetButtonStatus(this, 'btnsubmit')"></asp:TextBox><br />
Now, if I chose TextMode="MultiLine". my javascript function doesnt woprk. It works perfect if I remove multiline mode. I tried using textarea instead of textbox yet it didnt work. I also try having html button instead of asp.net button, yet it is not working.
Any help would be appreciated. Thanks.
这篇关于Javascript函数使用文本框但不使用TextArea和多行模式的文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!