Javascript函数使用文本框但不使用TextArea和多行模式的文本框。 [英] Javascript function working with textbox but not working with TextArea and textbox with multiline mode.
问题描述
我有一个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按钮,但它无法正常工作。
任何帮助将不胜感激。谢谢。
将您的代码更改为...无需检查first.value.length> = 1
askeyup
仅从TextBox
触发事件。
它正在工作,在我的最后测试。
function SetButtonStatus(发件人, target){
if (sender.value.length> = 1 )
document .getElementById(target).disabled = false ;
else
document .getElementById(target).disabled = 真跨度>;
}
代码工作正常!!
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.
Change your code to... There is no need to checkfirst.value.length >= 1
askeyup
Event is fired from thatTextBox
only.
It is working, tested at my end.
function SetButtonStatus(sender, target) { if (sender.value.length >= 1) document.getElementById(target).disabled = false; else document.getElementById(target).disabled = true; }
The code works fine !!
这篇关于Javascript函数使用文本框但不使用TextArea和多行模式的文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!