如何使用jQuery选择带文本的按钮

Vis*_*l B 4 jquery laravel

是否可以使用jQuery中的text属性选择按钮?

我试着像:

$.each(data, function(index, element){
    if(element.table_aval == 0)
    {
         var elmt = element.table_no;
         $('#table button[text='+elmt+']').css('color','red');
    }
});
Run Code Online (Sandbox Code Playgroud)

这可能吗?

Bre*_*ody 9

:contains选择允许您选择含有特定字符串的元素.

$(document).ready(function() {
  $('button:contains("Text")').css({'color': 'red'})
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Text</button>

<button>Something Different</button>
Run Code Online (Sandbox Code Playgroud)