我想判断一个文本框当你不输入时弹出一个提示对话框。提醒你输入。并前文本框的背景颜色马上变为红色。以突出显示当前输入位置..

解决方案 »

  1.   

    if (document.getElementById("TextBox1").value=="")
          {
            alert("请输入!");
            document.getElementById("TextBox1").style.backgroundColor ="red"
          }
      

  2.   

    if (document.getElementById("TextBox1").value=="") 
          { 
            alert("请输入!"); 
            document.getElementById("TextBox1").style="background:#933" ;
    document.getElementById("TextBox1").focus();
          }
      

  3.   

    if (document.getElementById("TextBox1").value=="") 
          { 
            alert("请输入!"); 
            document.getElementById("TextBox1").style.backgroundColor ="red" 
            document.getElementById("TextBox1").focus(); //最好是最后再让此文本框取得焦点
          }
      

  4.   

    <html> 
    <head> 
    </head> 
    <body> 
    请输入:<input id="txt" name="txt" onBlur="doI()" />
    <script type="text/javascript" language="javascript"> function doI(){
    var obj = document.getElementById("txt");
    if (obj.value==""){  
            alert("请输入内容!");  
    obj.style.backgroundColor ="red" ; 
    obj.focus(); 
    }
    else{
    obj.style.backgroundColor ="" ; 
    }
    }
    </script> 
    </body> 
    </html>