gpt4 book ai didi

jquery - 定位精确文本匹配 (jQuery)

转载 作者:行者123 更新时间:2023-12-01 02:58:34 25 4
gpt4 key购买 nike

我需要通过精确的文本匹配来定位多个类。我的代码的一半似乎可以工作(未选中复选框时文本具有紫色背景),但是当选中复选框以定位文本时,似乎没有发生任何事情......

if ($("input:checkbox:checked#checkbox-id").length > 0) {
$('#main-content-panel .entry').filter(function(index) {
return $(this).text() == "Text"; }).css
('backgroundColor', 'orange');
}

if ($("input:checkbox:not(:checked)#checkbox-id").length > 0) {
$('#main-content-panel .entry').filter(function(index) {
return $(this).text() == "Text"; }).css
('backgroundColor', 'purple');
}

jsFiddle:http://jsfiddle.net/KKfEF/

最佳答案

您应该监听 change 事件:

var $elem = $('#main-content-panel .entry').filter(function (index) {
return $(this).text() == "Text";
});
$('#checkbox-id').change(function () {
var color = this.checked ? 'orange' : 'purple';
$elem.css('backgroundColor', color);
}).change();

http://jsfiddle.net/drcpY/

关于jquery - 定位精确文本匹配 (jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14513273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com