jQuery无法从每个函数获取值 [英] Jquery cannot get value from each function

查看:64
本文介绍了jQuery无法从每个函数获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有输入字段的表. 我试图从具有相同类的输入字段集中获取值,并将其与每个具有不同类名的相邻输入进行比较. 我可以在输入中看到该值,但jquery将该值返回为空.

I am using tables with input fields in them. I am trying to get the value from set of input fields with same class and compare to each of its adjacent input with diffrent class name. I can see the value in the input but the value is returned empty by jquery.

$('.subtotal').each(function(){
        var price = $(this).parent().parent().find('td input.price');
        console.log(price.val());
 });

这是html.这些行将重复.

Here is the html. these rows will be repeated.

            <tr>
                    <td>
                        <input type="text" name="data[<?=$i?>][title]" class="title"/>
                        <ul class="order_search_title">

                        </ul>
                    </td>
                    <td>
                        <input type="text" name="data[<?=$i?>][author]" class="author"/>
                    </td>
                    <td>
                        <input type="text" name="data[<?=$i?>][isbn]" class="isbn"/>
                        <ul></ul>
                    </td>
                    <td>
                        <select hidden="hidden" name="data[<?=$i?>][qty]" id="" class="qty">

                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                        </select>

                    </td>
                    <td>
                        <input type="number"  name="data[<?=$i?>][price]" class="price" READONLY />

                    </td>
                    <td>
                        <input type="number" name="data[<?=$i?>][subtotal]" class="subtotal" READONLY/>

                    </td>
                    <td>
                        <a href="#" class="cleartext">clear</a> 
                    </td>
                    <td>
                        <img class="delete" src="<?=base_url()?>/imgs/delete25.png" />
                    </td>
                </tr>

推荐答案

您使用了错误的变量.使用价格代替pr

You're using the incorrect variable. Use price instead of pr

$('.subtotal').each(function(){
        var price = $(this).parent().parent().find('td input.price');
        console.log(price.val()); //This should be price not pr
 });

这篇关于jQuery无法从每个函数获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆