在TR之外获得最接近的隐藏值 [英] Getting Closest Hidden Value Outside TR

查看:168
本文介绍了在TR之外获得最接近的隐藏值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当行中的复选框被选中时,如何获得隐藏字段的值与类OriginalSuggestedQty?

以下是HTML的外观例如:

 < input class =OriginalSuggestedQtytype =hiddenvalue =5> 
< tr>
< td>
< input class =SuggestedQtyid =items_1__SuggestedQtytype =textvalue =9>
< input checked =checkedclass =suggestedtype =checkboxvalue =true>
< / td>
< / tr>

这就是我现在所拥有的:

<$ ($(this).is(:checked)){
var originalVal();
> = $(this).closest('。OriginalSuggestedQty')。val();
$(this).closest('tr')。find('。SuggestedQty')。val(originalVal);
}
});


解决方案

要匹配帖子中显示的确切HTML,可以使用这个:

  $(this).closest('tr')。prev()

这会一直进行到达到TR,然后选择紧接在前面的DOM元素,即输入。

这是正确的吗?还是在TR和输入之间还有其他元素?


How can I get the the value of the hidden field with the class "OriginalSuggestedQty" when a checkbox within the row is checked?

Here is what the HTML looks like:

<input class="OriginalSuggestedQty" type="hidden" value="5">
<tr>
    <td >
        <input class="SuggestedQty" id="items_1__SuggestedQty" type="text" value="9">
        <input checked="checked" class="suggested"type="checkbox" value="true">
    </td>
</tr>

This is what i currently have:

$(".suggested").change(function() {
    if ($(this).is(":checked")) {
        var originalVal = $(this).closest('.OriginalSuggestedQty').val();
        $(this).closest('tr').find('.SuggestedQty').val(originalVal);
    }
});

解决方案

To match the exact HTML shown in the post, you can use this:

$(this).closest('tr').prev()

That will step up until it reaches the TR and then select the immediately preceding DOM element, which is the input.
Is this correct or will you have other elements between the TR and the input?

这篇关于在TR之外获得最接近的隐藏值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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