asp.net执行JS函数后TextBox颜色值消失?
Colour value of TextBox vanishes after JS function is executed in asp.net?
当通过下面的JS函数设置属性时,TexBox的颜色属性消失(闪烁)。请指教,如何保留颜色属性?
(即单击按钮后,颜色(奇数为绿色,偶数为红色)闪烁,颜色变回空白)
function numbercheck() {
var num = document.getElementById("txtnum").value;
if (num == "") {
alert("Please Enter number")
} else {
if (num % 2 == 0) {
alert("You have entered even number");
document.getElementById("txtnum").style.backgroundColor = "green";
} else {
alert("You have enetered Odd number");
document.getElementById("txtnum").style.backgroundColor = "red";
}
}
}
<p> Please enter a Number :
<asp:TextBox ID="txtnum" runat="server"></asp:TextBox>
</p>
<asp:Button Text="Check Number" ID="btnnum" runat="server" OnClientClick="return numbercheck()" />
Please change your script function as
function numbercheck() {
debugger;
var num = document.getElementById("<%=txtnum.ClientID%>").value;
if (num == "") {
alert("Please Enter number")
} else {
if (num % 2 == 0) {
alert("You have entered even number");
document.getElementById("<%=txtnum.ClientID%>").style.backgroundColor = "green";
} else {`enter code here`
alert("You have enetered Odd number");
document.getElementById("<%=txtnum.ClientID%>").style.backgroundColor = "red";
}
}
}
and
<asp:Button Text="Check Number" ID="btnnum" runat="server" OnClientClick="return numbercheck()" CausesValidation="false" UseSubmitBehavior="false" />
当通过下面的JS函数设置属性时,TexBox的颜色属性消失(闪烁)。请指教,如何保留颜色属性?
(即单击按钮后,颜色(奇数为绿色,偶数为红色)闪烁,颜色变回空白)
function numbercheck() {
var num = document.getElementById("txtnum").value;
if (num == "") {
alert("Please Enter number")
} else {
if (num % 2 == 0) {
alert("You have entered even number");
document.getElementById("txtnum").style.backgroundColor = "green";
} else {
alert("You have enetered Odd number");
document.getElementById("txtnum").style.backgroundColor = "red";
}
}
}
<p> Please enter a Number :
<asp:TextBox ID="txtnum" runat="server"></asp:TextBox>
</p>
<asp:Button Text="Check Number" ID="btnnum" runat="server" OnClientClick="return numbercheck()" />
Please change your script function as
function numbercheck() {
debugger;
var num = document.getElementById("<%=txtnum.ClientID%>").value;
if (num == "") {
alert("Please Enter number")
} else {
if (num % 2 == 0) {
alert("You have entered even number");
document.getElementById("<%=txtnum.ClientID%>").style.backgroundColor = "green";
} else {`enter code here`
alert("You have enetered Odd number");
document.getElementById("<%=txtnum.ClientID%>").style.backgroundColor = "red";
}
}
}
and
<asp:Button Text="Check Number" ID="btnnum" runat="server" OnClientClick="return numbercheck()" CausesValidation="false" UseSubmitBehavior="false" />