JQ怎么控制多个文本框获取、失去鼠标焦点事件

解决方案 »

  1.   

    例如:
    <input name="inputbox01" type="text" value="old content 01">
    <script language="javascript" type="text/javascript">
    //需先引用jquery
    $('#inputbox01').trigger("focus");  //获取焦点
    $('#inputbox01').trigger("blur");  //失去焦点
    </javascript>
      

  2.   

    <input name="textbox" type="text" value="content">
    <script language="javascript" type="text/javascript">
    $('#textbox').trigger("focus"); //获取焦点
    $('#textbox').trigger("blur");  //失去焦点
    </javascript>
      

  3.   

    <input  type="text" value="请输入照片标签">
    <input  type="text" value="请输入照片标签">
    <input  type="text" value="请输入照片标签">
    <input type="text" value="请输入照片标签">
    在很多个文本下实现获取焦点使value的值清空,离开焦点显示value的值
      

  4.   

    <input type="text" value="请输入照片标签" onfocus="theforever_csdn1(this);" onblur="theforever_csdn2(this);">
    <input type="text" value="请输入照片标签" onfocus="theforever_csdn1(this);" onblur="theforever_csdn2(this);">
    <input type="text" value="请输入照片标签" onfocus="theforever_csdn1(this);" onblur="theforever_csdn2(this);">
    <input type="text" value="请输入照片标签" onfocus="theforever_csdn1(this);" onblur="theforever_csdn2(this);"><script type="text/javascript">
    function theforever_csdn1(obj){
    obj.oldVal=obj.value;
    obj.value="";
    }
    function theforever_csdn2(obj){
    obj.value=obj.oldVal;
    }
    </script>
      

  5.   

    刚在另外一个贴回答了一个一模一样的问题,果断直接拷过来。。<!DOCTYPE html>
    <html>
    <head>
        <title>test</title>
        <script src="jquery.js"></script>
    </head>
    <body>
        <form id="form" action="" method="get">
    <input type="text" name="First name" value="First name"/>
    <input type="text" name="Family name" value="Family name"/>
    <input type="text" name="Email" value="Email..."/>
    <input type="text" name="password" value="password..."/>
    <input type="text" name="location" value="City where you live"/>
    <input type="submit" name="sign up" value="Sign Up"/>
    </form>
        <script>
         $('#form').children(':text').focus(function(){
         if(!this.initValue){
    this.initValue = this.value;
    }
    if(this.value === this.initValue){
    this.value = '';
    }
         }).blur(function(){
    if(this.value === '' || this.value === null){
    this.value = this.initValue;
    }
    });
        </script>
    </body>
    </html>
      

  6.   

    JScript code<input name="textbox" type="text" value="content">
    <script language="javascript" type="text/javascript">
    $('#textbox').trigger("focus"); //获取焦点
    $('#textbox').trigger("blur");  //失去焦点
    </javascript>