<input type="text" name="txt_name" id="txt_name"  value="1" onfocus="txtFoc()" onblur="txtOnb()"  /><input type="submit" value="搜索" onclick="return nClick()"  />
function txtFoc(){
   var con=document.getElementById("txt_name");  
   if(con.value=="1")
   {
        con.value="";
   }else
   {
   con.focus();
   
   }
}
   function txtOnb()
   {
 
   var tname=document.getElementById("txt_name").value;
  想实现的是当鼠标离开焦点时..得到刚才传的值 然后赋值到text控件的value,而不是显示1..在线的帮忙 谢谢咯   }
    </script>

解决方案 »

  1.   

    var tname=document.getElementById("txt_name").value;
    document.getElementById("txt_name").value = tname;
      

  2.   

      if(con.value=="1")
      {
      con.value="";
      }
    你这写的什么意思啊?
      

  3.   

    你自己网上down一个好了 这么简单的问题还用得着纠结嘛 
      

  4.   

    <input type="text" name="txt_name" id="txt_name" value="1" onfocus="txtFoc()" onblur="txtOnb()" /><input type="submit" value="搜索" onclick="return nClick()" />
    function txtFoc(){
      var con=document.getElementById("txt_name").value;   
      if(con=="1")
      {
      con="";
      }else
      {
      con.focus();
        
      }
    }
      function txtOnb()
      {
      
      var tname=document.getElementById("txt_name").value;
      想实现的是当鼠标离开焦点时..得到刚才传的值 然后赋值到text控件的value,而不是显示1..在线的帮忙 谢谢咯  }
      </script>
      

  5.   

     function test()
       {
          var s=document.getElementById("txt_name").value;
          if (s==1)
          {
             document.getElementById("txt_name").value="";
          }
          else
          {
             document.getElementById("txt_name").focus();
          }
       }说实话,还真没明白嘛意思。这是输入1的话,置空。。
      

  6.   

       function fucus() {
              var a = document.getElementById("ipt").value;
              if (a == "1") {
                  document.getElementById("ipt").value = "";
              }
          }
          function blur() {
              var aa = document.getElementById("ipt").value;
              if (aa == "") {
                  document.getElementById("ipt").value = "1";
              }
          }
    <input id="ipt" value="1" onfocus="fucus()" onblur="blur()" type="text" />
      

  7.   

    text 默认值是1  然后传了一值  是2  想实现的就是当我失去焦点时...... text就会变成2 也不是这个默认值1
      

  8.   

    [Quote=引用 6 楼 woanon 的回复:]你想把输入框里面输入的1都重置为空值?
    [/Quotetext 默认值是1 然后传了一值 是2(值都可以) 想实现的就是当我失去焦点时...... text就会变成2 也不是这个默认值1
      

  9.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JS.aspx.cs" Inherits="QuestionForCsdn.JS" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>    <script type="text/javascript">
            function txtFoc() {
                var con = document.getElementById("txt_name");
                if (con.value == "通过") {
                    con.value = "中国";
                } else {
                    con.focus();
                }
            }
            function txtOnb() {
                var tname = document.getElementById("txt_name").value;
                document.getElementById("txt_name").value = tname;
                document.getElementById("txt_name").focus();
                return false;
            }
        </script></head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input type="text" name="txt_name" id="txt_name" value="通过" onmouseout="txtFoc()" onblur="txtOnb()" />
            <input type="button" value="搜索" onclick="return txtFoc()" />
        </div>
        </form>
    </body>
    </html>
      

  10.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>水印案例</title>
    <script>
     function $(id)
     {
     return document.getElementById(id);
     }
     function b()
     {
       $("txt1").value="";
     }
     function c()
     {
       $("txt1").value="请输入用户名";
     }
    </script>
    </head><body>
    <input  type="text" id="txt1"  onfocus="b()" onblur="c()"/>
    </body>
    </html>
    最简单的