Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从选定复选框旁边的文本框中获取选定文本_Javascript_Jquery_Html - Fatal编程技术网

Javascript 从选定复选框旁边的文本框中获取选定文本

Javascript 从选定复选框旁边的文本框中获取选定文本,javascript,jquery,html,Javascript,Jquery,Html,我有一个表,其中包含一个复选框、一些文本和一个选择框。用户将选中一个复选框,然后在选择框中选择一个值。我试图找出用户是否在对应于复选框的选择框中选择了一个值 以下是我的代码: $(文档).ready(函数(){ console.log(“准备就绪!”); $(“#提交”)。单击(函数(){ $(“.cb:checked”).each(函数(){ var cb=$(本); log(cb.find('select option:selected').text()); if(cb.find('sel

我有一个表,其中包含一个复选框、一些文本和一个选择框。用户将选中一个复选框,然后在选择框中选择一个值。我试图找出用户是否在对应于复选框的选择框中选择了一个值

以下是我的代码:

$(文档).ready(函数(){
console.log(“准备就绪!”);
$(“#提交”)。单击(函数(){
$(“.cb:checked”).each(函数(){
var cb=$(本);
log(cb.find('select option:selected').text());
if(cb.find('select option:selected')。text()=“-”){
cb.find('select').css(“边框颜色”、“红色”);
}
})
});
});

一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
拯救
我使用了
最近的()
来访问
tr
父标记,然后应用
find
来访问相应的复选框

$(文档).ready(函数(){
console.log(“准备就绪!”);
$(“#提交”)。单击(功能(e){
$(“.cb:checked”).each(函数(){
var cb=$(本);
console.log(cb.closest('tr').find('select option:selected').text());
if(cb.closest('tr').find('select option:selected').text()==“-”){
cb.closest('tr').find('select').css(“边框颜色”、“红色”);
}
})
});
});

一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
拯救
我使用了
最近的()
来访问
tr
父标记,然后应用
find
来访问相应的复选框

$(文档).ready(函数(){
console.log(“准备就绪!”);
$(“#提交”)。单击(功能(e){
$(“.cb:checked”).each(函数(){
var cb=$(本);
console.log(cb.closest('tr').find('select option:selected').text());
if(cb.closest('tr').find('select option:selected').text()==“-”){
cb.closest('tr').find('select').css(“边框颜色”、“红色”);
}
})
});
});

一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
一些文本
-
abc
def
ghi
拯救
您正在对每个复选框使用
.find()
,该复选框搜索后代元素,但您的选择框不是复选框的后代

您可以将
.closest()
.find()
组合,以针对与当前复选框对应的所选选项:

$(this).closest('tr').find('option').filter(':selected')

您正在对每个复选框使用
.find()
,该复选框搜索子元素,但您的选择框不是复选框的后代

您可以将
.closest()
.find()
组合,以针对与当前复选框对应的所选选项:


$(this).closest('tr').find('option').filter(':selected')

只需将脚本代码更改为

$(文档).ready(函数(){
console.log(“准备就绪!”);
$(“#提交”)。单击(函数(){
$(“.cb:checked”).each(函数(){
var cb=$(this.parent().parent();
log(cb.find('select option:selected').text());
if(cb.find('select option:selected')。text()=“-”){
cb.find('select').css(“边框颜色”、“红色”);
}
其他的
cb.find('select').css(“边框颜色”);
})
});

});只需将脚本代码更改为

$(文档).ready(函数(){
console.log(“准备就绪!”);
$(“#提交”)。单击(函数(){
$(“.cb:checked”).each(函数(){
var cb=$(this.parent().parent();
log(cb.find('select option:selected').text());
if(cb.find('select option:selected')。text()=“-”){
cb.find('select').css(“边框颜色”、“红色”);
}
其他的
cb.find('select').css(“边框颜色”);
})
});
});