[英]What is the correct way to use PARENT and FIND?
I try to get the value of input type=text by finding it in the parent DIV with class "half_weight" . 我尝试通过在类“half_weight”的父DIV中找到它来获取input type = text的值。 But I get the result NaN and it should be 0.8.
但我得到结果NaN ,它应该是0.8。
This is HTML: 这是HTML:
<div class="add_controller amt no_space half_weight">
<div class="col s2 adds">
<a id="" href="#" class="button-minus product_quantity_down">
<i class="material-icons">remove</i>
</a>
</div>
<div class="col s2 adds">
<a href="#" class="button-plus product_quantity_up">
<i class="material-icons">add</i>
</a>
</div>
<div class="col s5 qty">
<div class="row">
<span class="col s6 qty_value">
<input type="text" name="" id="" stepquan="0.8" rtype="2" value="0.8" class="text" />
</span>
</div>
</div>
This is my jQuery: 这是我的jQuery:
$('.button-plus').on('click', function() {
valTemp = parseFloat($(this).parent('.half_weight').find('.qty_value').siblings('input[type=text]').val());
alert(valTemp);
});
You don't need siblings()
(it refers to neighbors and you have got parent-child relationship). 你不需要
siblings()
(它指的是邻居,你有亲子关系)。 I put just 我放了
$(this).parents(".half_weight").find('.qty_value input[type=text]').val();
and it shows 0.8. 它显示0.8。
$('.button-plus').on('click', function() { var valTemp = parseFloat($(this).parents(".half_weight").find('.qty_value input[type=text]').val()); alert(valTemp); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="add_controller amt no_space half_weight"> <div class="col s2 adds"> <a id="" href="#" class="button-minus product_quantity_down"> <i class="material-icons">remove</i> </a> </div> <div class="col s2 adds"> <a href="#" class="button-plus product_quantity_up"> <i class="material-icons">add</i> </a> </div> <div class="col s5 qty"> <div class="row"> <span class="col s6 qty_value"> <input type="text" name="" id="" stepquan="0.8" rtype="2" value="0.8" class="text" /> </span> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.