<td><input id= name="knowFrom" type="checkbox" value="" /> TV</td>如何取出这个checkbox后面跟的文本?

解决方案 »

  1.   

    id= name="knowFrom"
    真有才
      

  2.   

    加个<label>标签,或者<span>标签;
    取标签的Text
      

  3.   

    $("#knowFrom").find("input[type='checkbox']:checked").siblings().text();
      

  4.   

    <td><input id= name="knowFrom" type="checkbox" value="" /> <label>TV</label></td>
    $("#knowFrom").next().text()
      

  5.   

    修正一下:<td><input name="knowFrom" type="checkbox" value="" /> TV</td>function getSelectedText(name) {
    // if (2>1) return "";
        var value = "";
        $(":input[name='"+name+"']").filter("[checked=true]").each(function() {
         var $obj=this;
            if (this.checked) {
                if (value == "") value += $obj.siblings().text();
                else value += "-" + $obj.siblings().text();
            }
        });    return value;
    }用3楼的办法,在控制台中报错说siblings()不是函数.不能改html,因为定义了很多样式,修改成label的css可能失效,css是美工做的.
      

  6.   

    可以把TV设置成checkbox这个标签的value值。
      

  7.   

    关键这不只是一个checkbox,是一组,你这个办法不行,即使只有一个,取出还要再做很多处理才能得到文本。
      

  8.   

    获取checkbox父节点的text$("input[checked]").parent().text()
    OR
    $("#knowFrom").parent().text()
      

  9.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GBK">
    <title>Untitled Document</title>
    <script language="JavaScript" src="js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
    $(function(){
    $("#_but").click(function(){
    $("input[name='knowFrom'][checked]").each(function(){
    alert($(this).parent().text());
    });
    });

    });
    </script>
    </head>
    <body>
    <table>
    <tr>
    <td><input name="knowFrom" type="checkbox" value="1" />TV11</td>
    </tr>
    <tr>
    <td><input name="knowFrom" type="checkbox" value="2" />TV2</td>
    </tr>
    <tr>
    <td><input name="knowFrom" type="checkbox" value="3" />TV321</td>
    </tr>
    <tr>
    <td><input name="knowFrom" type="checkbox" value="4" />TV4000</td>
    </tr>
    </table>
    <input type="button" name="but" id="_but" value="取text">
    </body>
    </html>
      

  10.   


    $("input[type='checkbox']).each(function(i){
    $(this).innerHTML
    })
      

  11.   

    爲什麽要把input跟文本放在一起,另外放個TD就好了
      

  12.   


    text()返回满足条件的所有文本,应该不用再写函数了吧
      

  13.   

    直接给个ID  $(#ID名).text();不就有了么
      

  14.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=GBK">
            <title>Untitled Document</title>
            <script language="JavaScript" src="js/jquery-1.4.2.min.js"></script>
            <script type="text/javascript">
                $(function(){
                    $("#_but").click(function(){
                        var checks = $("input[name='knowFrom']:checked");
        $.each(checks,function(idx,obj){
                          alert($(obj).parent("td").text());
                         })
                    });
                    
                });
            </script>
        </head>
        <body>
                <table>
                    <tr>
                        <td><input name="knowFrom" type="checkbox" value="1" />TV11</td>
                    </tr>
                    <tr>
                        <td><input name="knowFrom" type="checkbox" value="2" />TV2</td>
                    </tr>
                    <tr>
                        <td><input name="knowFrom" type="checkbox" value="3" />TV321</td>
                    </tr>
                    <tr>
                        <td><input name="knowFrom" type="checkbox" value="4" />TV4000</td>
                    </tr>
                </table>
                <input type="button" name="but" id="_but" value="取text">
        </body>
    </html>
    这个效果么?
      

  15.   

    解决了,this要用在jquery的写法时,不能直接使用,要$(this)才行,好奇怪呀。可以不必这么麻烦,像我这样写也可以:        <script type="text/javascript">
                $(function(){
                    $("#_but").click(function(){
                        var checks = $("input[name='knowFrom']:checked");
                $.each(checks,function(){
                          alert($(this).parent().text());
                         })
                    });
                    
                });
            </script>