var $label = $('label');
//How can I select a `label` using attribute selector, something like below.
$label['data-id=1'].text('some value');
//There is no such a syntax, I am just trying to explain what I need to do.
您可以使用filter
从$label
获取匹配的ID标签,然后设置文本值。参见下面的代码
var id = $(this).find('.form-control-data-id').text();
var val = $(this).find('.form-control').val();
$label.filter(function(){
return id == $(this).data('id');
}).text(val);