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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37088816/
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-09-14 13:44:54  来源:igfitidea点击:

How to select button with text using jQuery

jquerylaravel

提问by Vishal B

Is it possible to select buttons using the text property in jQuery?

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

I was trying like:

我试着像:

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

Is this possible?

这可能吗?

回答by Brett DeWoody

The :containsselectorallows you to select elements containing a specific string.

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

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

<button>Something Different</button>

回答by Rajeesh Madambat

$.each(data, function(index, element){
    if(element.table_aval == 0){
       var elmt = element.table_no;
       $("button:contains(text='+elmt+')").css('color','red');
}});