This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                6年前关闭。
            
        

有什么方法可以获取此表中跨度.vypis的文本值吗?
我需要使用.vypis上的快捷键访问相应的.key

PHP和HTML:

<table>
    <tr>
      <td><input id="textarea" class="key" type="text" name="item-ks" value="1"/></td>
      <td><span class="vypis">5</span>" /></td>
    </tr>
</table>


JAVASCRIPT:

$(function(){
    $(".key").keyup(function(){
        var value = $(this).val(); // works
        var text = $(this).find(".vypis").text(); // doesn't work
        alert(text); // test is null
        $('.vypis').text(value * text);
    })
});


谢谢您的帮助。

最佳答案

输入和跨度元素嵌套在TD的_中

$(this).closest('td').next('td').find(".vypis").text();


所以所有人都这样:

$(function(){
    $(".key").on('keyup', function(){
        var value = this.value,
        $(this).closest('td').next('td').find(".vypis").text(function(_,txt) {
            return parseInt(txt, 10) * parseInt(value, 10);
        });
    });
});

07-24 19:32
查看更多