如何在javascript中更改文本框backgroundcolor [英] how to change textbox backgroundcolor in javascript

查看:111
本文介绍了如何在javascript中更改文本框backgroundcolor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function mycheck1() {

          var txt1 = document.getElementById("<%=txt1.clientid%>");

          if (txt1.value == "") {

             // alert("It is Empty");

              txt1.style.background = "#FFF000";
          }

      }





asp:TextBox runat='server' ID='txt1'></asp:TextBox>
       <asp:CustomValidator runat="server" ID='cv1' ControlToValidate='txt1' ClientValidationFunction='mycheck1'
           ValidateEmptyText='true'  ></asp:CustomValidator>
           <asp:Button runat='server' ID='btn1' Text='submit' />

推荐答案

var v = document.getElementById("<%=TextBox1.ClientID%>");
            v.style.backgroundColor = "red";


检查该线程

如何在XHTML中设置文本框的背景色表格! [
Check this thread

How to set backgroundcolor of a textbox in an XHTML form![^]


我认为您无需查看客户端ID.这本身应该起作用:

I don''t think you need to look at client id. This itself should work:

var txt1 = document.getElementById(''txt1'');


这篇关于如何在javascript中更改文本框backgroundcolor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆