asp.net文本框javascript函数不工作/解雇? [英] asp.net textbox javascript function not working/firing?
问题描述
我的文本框:
< asp:TextBox ID = TextBox2 runat = server MaxLength = 40 Width = 325px BackColor = LightSalmon / >
javascript:
< ; script type < span class =code-keyword> = text / javascript 语言 = javascript >
function checkFilled(){
var inputVal = document.getElementById(dnn $ ctr445 $ View $ TextBox2)。value;
if(inputVal ==){
document.getElementById(dnn $ ctr445 $ View $ TextBox2)。style.backgroundColor =lightsalmon;
}
else {
document.getElementById(dnn $ ctr445 $ View $ TextBox2)。style.backgroundColor =white;
}
}
< / script >
pageload:
TextBox2.Attributes.Add( onchange,javascript:checkFilled())
我的文本框位于更新面板中。我想要完成的是文本框背面的颜色是空的浅红色。当用户输入时,背面颜色将变为白色,如果他们删除文本框文本,它将变回浅红色。这只是用于视觉辅助,而不是实际处理任何验证。
我不使用大量的javascript所以我不确定我的页面加载部分是否正确。
任何人都可以帮我解释为什么这段代码无效?
ctr445
查看
TextBox2)。value;
if(inputVal ==){
document.getElementById( DNN
my textbox:
<asp:TextBox ID="TextBox2" runat="server" MaxLength="40" Width="325px" BackColor="LightSalmon" />
javascript:
<script type="text/javascript" language="javascript">
function checkFilled() {
var inputVal = document.getElementById("dnn$ctr445$View$TextBox2").value;
if (inputVal == "") {
document.getElementById("dnn$ctr445$View$TextBox2").style.backgroundColor = "lightsalmon";
}
else {
document.getElementById("dnn$ctr445$View$TextBox2").style.backgroundColor = "white";
}
}
</script>
pageload:
TextBox2.Attributes.Add("onchange", "javascript:checkFilled()")
my textbox is in an updatepanel. what I am trying to accomplish is the textbox back color is light red when empty. When a user types into it, the back color will turn white, and if they delete the textbox text it will turn back to light red. This is just for visual aid and not actually handling any validations.
I don't use a whole lot of javascript so I am not sure if my pageload part is correct.
can anyone give me a hand with why this code isn't working?
ctr445
View
TextBox2").value; if (inputVal == "") { document.getElementById("dnn
这篇关于asp.net文本框javascript函数不工作/解雇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!