如何使用jQuery按特定文本选择按钮 [英] how to select button by particular text using jquery
问题描述
我正在尝试使用jquery更改按钮的CSS,但是我无法使用text属性找到按钮,我的JQuery是:
I am trying to change CSS of button using jquery, but i am not able to find the button using text property, my JQuery is:
$.ajax({
url : "{{url('booktable')}}",
type : "GET",
data : {},
success : function(data){
$.each(data, function(index, element){
if(element.table_aval == 0)
{
var elmt = element.table_no;
$('#table button[text='+elmt+']').css('color','red');
}
});
}
});
按钮是由foreach循环创建的一组按钮,这就是为什么我尝试使用text属性查找它的原因,我该怎么做,按钮是:
buttons are group of button created by foreach loops, thats why I am trying to find it using text attribute, how can i do that, buttons are:
<tbody>
@foreach($tables as $table)
<tr id="">
<!--input type="hidden" name="table_no" id="tno" value=""-->
<td style="text-align: center;">
<button class="btn" >{{$table->table_no}} </button>
</td>
</tr>
@endforeach
</tbody>
推荐答案
也许此代码可以为您提供帮助: https://jsfiddle.net/auczzk5x/
Maybe this code will help you: https://jsfiddle.net/auczzk5x/
您用以下单词填充文本输入: special 或 unspecial .并且下面的按钮具有text
属性,其值为其中一个单词.例如,如果您键入 special 并单击 Clorize Buttons ,则带有text="special"
的按钮将显示为红色.
You fill a text input with word: special or unspecial. And buttons below have text
atributte with value of one of these words. For example, if you type special and click Clorize Buttons than buttons with text="special"
will be in red color.
在上面的代码中,没有在jQuery代码中使用的带有id="table"
的HTML元素:$('#table button[text='+elmt+']')
,这表明按钮位于带有id="table"
的元素中.
In your code above there is no HTML element with id="table"
, that you use in jQuery code: $('#table button[text='+elmt+']')
, what suggests that buttons are in element with id="table"
.
这篇关于如何使用jQuery按特定文本选择按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!