Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在多个类上迭代jquery函数_Jquery - Fatal编程技术网

在多个类上迭代jquery函数

在多个类上迭代jquery函数,jquery,Jquery,我正在尝试完成这个jquery函数。目标是输入单个值并在每个表单元格中返回正确的百分比。我让它工作,以便它填充第一个单元格,但我希望这些类都是相同的,并且有一个输入,用输入的百分比填充每个单元格 <input class="max1" /> <table> <tr> <td colspan="5">Deadlift</td> </tr> <tr> <t

我正在尝试完成这个jquery函数。目标是输入单个值并在每个表单元格中返回正确的百分比。我让它工作,以便它填充第一个单元格,但我希望这些类都是相同的,并且有一个输入,用输入的百分比填充每个单元格

<input class="max1" />
<table>
    <tr>
        <td colspan="5">Deadlift</td>
    </tr>
    <tr>
        <td align="center">
            <span  class="perc1">75</span>% x 3</td>
        <td align="center">
            <span class="perc">78</span>% x 2</td>
        <td align="center">
            <span class="perc">83</span>% x 1</td>
        <td align="center">
            <span class="perc">85</span>% x 1</td>
    </tr>
    <tr>
        <td class="weight1"></td>
        <td class="weight"></td>
        <td class="weight"></td>
        <td class="weight"></td>
    </tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function () {
    $('input').keyup(function () {
        cal(this);
    });
});

function cal(obj) {
    var cal1, perc1, result;
    cal1 = parseFloat(obj.value);
    perc1 = parseFloat($('.perc1').text());


    result = (cal1*perc1)/100;
    $('.weight1').html(result);
}
</script>

硬举
75%x3
78%x2
83%x1
85%x1
$(文档).ready(函数(){
$('input').keyup(函数(){
cal(本);
});
});
功能校准(obj){
var cal1,perc1,结果;
cal1=解析浮点(对象值);
perc1=parseFloat($('.perc1').text());
结果=(cal1*perc1)/100;
$('.weight1').html(结果);
}
试试这个

$(文档).ready(函数(){
$('input').keyup(函数(){
cal(本);
});
});
功能校准(obj){
var cal1,perc1,结果;
cal1=解析浮点(对象值);
$.each($(“.perc”),函数(键,val){
var perc1,结果;
perc1=parseFloat($(val).text());
结果=(cal1*perc1)/100;
$($('.weight')[key]).html(结果);
});
}

硬举
75%x3
78%x2
83%x1
85%x1

好的,根据您的描述,我认为您需要一个简单的
$。每个
迭代所有td span并像这样设置您的输入百分比

$('table').find('tr:not(:first)').find('td').each(function() {
   $this = $(this);
   $this.find("span.perc").html('your value');
});

你能说清楚一点吗?那我们就可以帮你完成这项工作了!非常感谢你的帮助。我不太明白如何实现.each()函数以正确迭代。@t如果这个答案解决了您的问题,您应该接受这个答案。通过点击右边的符号。@nishan,如果您不介意的话,您能帮我演示一下如何在同一页上的多个表中实现这一点吗?例如,3个输入和3个表,每个输入只对应于它下面的表。如果要求不太高,我将不胜感激