如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
同级下确定最后的input
$(this).parent('.number').children("input").last().val(mm);
//html <form method="post" action="__APP__/default/fill_info.html"> <div class="ticket_species_3"> <span class="ticket">儿童价</span> <div class="number"> <input type="button" value="-" class="jian" /> <span>1</span> <input type="button" value="+" class="jia" /> <input type="hidden" name="et" value="1" class="et"> </div> <span class="price">¥50</span> </div> <div class="ticket_species_3"> <span class="ticket">成人价</span> <div class="number"> <input type="button" value="-" class="jian zj" /> <span class="cr_num">1</span> <input type="button" value="+" class="jia zj" /> <input type="hidden" name="cr" value="1" class="cr"> </div> <span class="price">¥100</span> </div> <div class="ticket_species_4"> <input type="reset" value="取消" class="qxbtn"> <input type="submit" value="确定" class="surebtn" > </div> </form> //jq $(".ticket_species_3 .number .jian").on("click",function(){ var mm = parseInt($(this).next("span").text()); if(mm >0){ var mm = mm-1; $(this).next("span").text(mm); $(this).parent('.number').children("input").last().val(mm); }else{ $(this).next("span").text("0"); $(this).parent('.number').children("input").last().val('0'); } }) $(".ticket_species_3 .number .jia").on("click",function(){ var mm = parseInt($(this).prev("span").text()); var mm = mm+1; $(this).prev("span").text(mm); $(this).parent('.number').children("input").last().val(mm); })