比较文本和字符串jQuery
let teste = $('.btn-timer').text().trim();
condition = '15:00'
//let result = teste.localeCompare(condition);
//console.log(result);
if (teste == condition) {
$('.btn-timer').removeClass('btn-success');
$('.btn-timer').addClass('btn-danger');
}
console.log(teste);
console.log(condition);
.btn-danger {
color: #991C32 !important;
background-color: #FFB2C0 !important;
border-color: #C82442 !important;
}
.btn-success {
color: #234D31 !important;
background-color: #B2FFCD !important;
border-color: #449560 !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btn btn-success shadow btn-timer td-content">
<b>15:00</b>
</button>
我试图实现一个将类()与字符串比较text()的代码:
我尝试了很多事情,但是没有运气,有什么帮助吗?
我做错了什么?以及如何填充它
let teste = $('.btn-timer').text().trim();
condition = '15:00'
//let result = teste.localeCompare(condition);
//console.log(result);
if (teste == condition) {
$('.btn-timer').removeClass('btn-success');
$('.btn-timer').addClass('btn-danger');
}
console.log(teste);
console.log(condition);
.btn-danger {
color: #991C32 !important;
background-color: #FFB2C0 !important;
border-color: #C82442 !important;
}
.btn-success {
color: #234D31 !important;
background-color: #B2FFCD !important;
border-color: #449560 !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btn btn-success shadow btn-timer td-content">
<b>15:00</b>
</button>
I'am trying to implement a code that compare a text() from class with a string:
I tried a lot of things, but without luck, any help?
What I am doing wrong? and how to fiz it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑以下示例,对于同一类的多个按钮。
使用
.each()
我们可以迭代每个元素。请参阅更多:您也可以使用更直接的选择器。
请参阅更多:
Consider the following example, for multiple buttons of the same class.
Using
.each()
we can iterate each element. See More:You can also use a more direct Selector.
See More: