javascript 在javascript函数中获取最接近的tr值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7500046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 00:19:23  来源:igfitidea点击:

Get the closest tr value in javascript function

javascriptjqueryjavascript-events

提问by Yasitha

I am having table which contain some data. This table is generating using a component. All td's has the same class name. Each row begins with a check-box with a specific value to that row. When click on a td on that row I want to get check-box value. When I click on a label javascript function is trggers. Cannot use Jquery click function.

我有包含一些数据的表格。该表是使用组件生成的。所有 td 都具有相同的类名。每一行都以一个复选框开始,该复选框具有该行的特定值。当单击该行上的 td 时,我想获取复选框值。当我点击一个标签时,javascript 函数是 trggers。无法使用 Jquery 点击功能。

回答by Samich

sample: http://jsfiddle.net/gCGVJ/

示例:http: //jsfiddle.net/gCGVJ/

$('td').click(function() {
    alert($(this).closest('tr').find('input[type=checkbox]').val());
});

回答by Kanishka Panamaldeniya

$('td').click(function(){

    var val = $(this).closest('tr').find('#checkbox').val();

});