<td><input type="text" id="t_Type"><input type="button" id="btnSearch" value="搜索"></td>
<td><input type="text"id="b_Brand"></td>我现在给 b_Brand注册了blur 事件, 我想在这个事件里面获取到 b_Brand 的值和 t_Type的值,
同样如果我有第三个文本框我要获取 前面二个文本框的值

解决方案 »

  1.   


    function on_blur()
    {
     var v1 = $('t_Type').val();
     var v2 = $('b_Brand').val();
     //......
     alert(v1);
     alert(v2);
    }
      

  2.   

    $("#b_Brand").prevAll().find("input[type='text']")
      

  3.   

    1楼的方法肯定不行呀 我之所有这样问肯定是页面中有多个相同的ID 或者 CLASS
    这位哥们不行呀,得到的是object 哪里写错了
      

  4.   

    $("#b_Brand").prevAll().find("input[type='text']").each(function(){
       alert($(this).val());
    });我以为写个选择器你就知道了
      

  5.   

    获取所有的text框的值$(function()
    {
     $(":text").each(function()
      {
        alert(this.value);
      });
    });
      

  6.   


    楼上几位没明白我的意思 ,只有这位哥们明白了, 但是我还是取不到值, 不知道什么原因.
    这是我代码  找到所有class="c_Brand" 注册一个blur 然后获取前面上一个节点的文本框值.
    $(".c_Brand").blur(function(){
                    
                   $(".c_Brand").prevAll().find("input[type='text']").each(function(){
                      alert($(this).val());
                    });
                 });这代码感觉是对的但是没值.
      

  7.   

    这样呢?
     $(".c_Brand").blur(function(){
        
      $(".c_Brand").prevAll("input[type='text']").each(function(){
      alert($(this).val());
      });
      });
      

  8.   

    理论上上面代码是对的啊!
    alert($(".c_Brand").prevAll().find("input[type='text']").html());打印一下html值看看获取到没。慢慢找错吧!只能靠你自己了
    说破天也就是上面的方法了。
      

  9.   

    prevAll().查找当前元素之前所有的同辈元素
    你去 <...掉索"></td>
    <td><input....>中间的TD成了
      

  10.   

    为什么打印出来的html是null 奇怪呀,郁闷 我也感觉那代码好像是对的,哎.
      

  11.   

    [Quote=引用 10 楼 alxw4616 的回复:]
    引用楼主 ilove_aspnet 的回复:
    你是说把<td></td>去掉?
      

  12.   


    我试过了,prevAll 是列出级别的,find 是用于查找后代的即包含关系的,如 <div><span></span></div>
    如果不明确可以打出 alert($(".c_Brand").prevAll("input[type='text']").size())这个应该是对的,刚测试了下$(".c_Brand").blur(function(){
        
      $(".c_Brand").prevAll("input[type='text']").each(function(){
      alert($(this).val());
      });
      });
      

  13.   

    我的size 是0 html 也是NULL 可能上面的代码是对的但是我HTML 也感觉不出来哪里有错,
    谢谢大家的回答, 看能否帮我看看<td>
           <input type="text" id="txtType" class="c_Type" /><input class="btnType" id="Button1" type="button"/>123
                    </td>
                    <td>
                        <input type="text" id="txtBrand" class="c_Brand" />
                    </td>
      

  14.   


    <!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>test</title>
    <script src="jquery-1.3.2.js"></script>
    <script>
    $(function(){
    $("#b_Brand").blur(function(){
    var t_Type = $(this).parent("td").prev().children("[type=text]").val();
    alert(t_Type)
    var btnSearch = $(this).parent("td").prev().children("[type=button]").val();
    alert(btnSearch)
    });

    });
    </script>
    </head><body>
    <table>
        <td><input type="text" id="t_Type" /><input type="button" id="btnSearch" value="搜索" /></td>
        <td><input type="text"id="b_Brand" /></td>
    </table>
    </body>
    </html>
      

  15.   

    你去掉 <td></td> 就能找到了.
      

  16.   

    谢谢这个可以,  还有个问题就是如果是第三个文本框事件也可以获取前面两个TD里面的text不,  很感谢大家这么支持我, 谢谢..
      

  17.   

    贴个全的吧。没代码没真相。<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
    <script>
    $(function()
    {
      $(".c_Brand").bind('blur',function(){
      //alert($(this).prevAll("input[type='text']").size());
      $(this).prevAll("input[type='text']").each(function(){  
      alert($(this).val());
      //alert($(this).html());// 注意input没有html
      });
      });
      
    });
    </script>  <td>
      <input type="text" id="txtType" class="c_Type" />
      <input class="btnType" id="Button1" type="button"/>123
      </td>
      <td>
      <input type="text" id="txtBrand" class="c_Brand" />
      </td>
      

  18.   

    这种方式要去掉td 
    这位的 lieri111  可以,但是不知道怎么递归 就是我第三个还要获取前面td1 和td2的值
      

  19.   


    <td><input type="text" id="t_Type"><input type="button" id="btnSearch" value="搜索"></td>
    <td><input type="text"id="b_Brand"></td>
    因为有多个不建议用id,故这里的id都是name了。
    -----------------
    <td><input type="text" name="t_Type"><input type="button" name="btnSearch" value="搜索"></td>
    <td><input type="text" name="b_Brand"></td>
    $(function () {
        $("input[name='b_Brand']").blur(function () {
              var c = $(this);
              alert("Brand:" + c.val());
              var type = c.parent().prev("td").find("input[name='t_Type']").val();
              alert("type:" + type);
        });
    });