gpt4 book ai didi

javascript - 将选中的属性添加到 TR 中最接近的复选框

转载 作者:行者123 更新时间:2023-12-03 07:37:06 24 4
gpt4 key购买 nike

当数量文本输入更改(向上/向下)时,我希望同一 TR 行上的复选框获得“已检查”属性。

到目前为止我的尝试:
我怀疑它与 .closest 的使用是一致的,但我已经完全明白了,这是我到目前为止的做法:

function addCheck() {
$('table.table-bordered input[type="checkbox"]').each(function() {
// get current row
parent = $(this).closest('tr');
// in row find input and add the value
$('#option-value-417').attr( 'checked', 'checked' );
});
}

文本输入然后添加了功能,准备就绪:

onchange="addCheck();"

目前我已经对复选框 ID 号进行了硬编码。

网站网址:http://rlpetproducts2.designlocker.co.uk/index.php?route=product/product&product_id=251

enter image description here

最佳答案

尝试以下 jquery 片段:

 $('input[type="text"]').on('change',function(){
$(this).closest('tr').find('input[type="checkbox"]').attr( 'checked', 'checked' );
});

或者

 $('input[type="text"]').on('change',function(){
$(this).closest('input[type="checkbox"]').attr( 'checked', 'checked' );
});

关于javascript - 将选中的属性添加到 TR 中最接近的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35563751/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com