白日梦想jun 2016-10-30 03:04 采纳率: 100%
浏览 783

jq 中选择器的问题,急,谢谢

    我想通过点击复选框得到文本框输入的值,下面的选择器错在哪里的啊??
    <form action="doShopping.jsp" id="order_shopping" name="order_shopping" onsubmit="return checkShopping();">
        <table id="table" class="fl">
            <tbody>
                <tr>
                    <th>商品名</th>
                    <th>单价</th>
                    <th>购买数量</th>
                    <th><input id="both" type="checkbox" name="both" autocomplete="off"></th>
                </tr>
                <tr>
                    <td>香蕉</td>
                    <td>100</td>
                    <td>
                        <input type="text" name="count" placeholder="请输入数量" autocomplete="off"/>
                    </td>
                    <td>
                        <input type="checkbox" name="choice" autocomplete="off">
                    </td>
                </tr>
            </tbody>
        </table>
        <input type="submit" id="add_shopping" value="添加购物车"/>
    </form>

    <script type="text/javascript">
    $(function(){
    var $current_count = $("#order_shopping #table tr td> input[name='choice']:checked").parent().prev().find("input[name='count']").val();
        console.log($current_count);
})
</script>
  • 写回答

2条回答 默认 最新

  • threenewbee 2016-10-30 03:24
    关注

    问题是你的输入框name="both"不是count

    评论

报告相同问题?

悬赏问题

  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退