gpt4 book ai didi

jquery - 使用属性 'title' 更改 css 项

转载 作者:行者123 更新时间:2023-11-28 09:03:26 24 4
gpt4 key购买 nike

只是试图让它根据标题中的内容重新设置每个元素的样式到目前为止,它只根据第一个更改它而忽略其他的。当我使用“each()”时,它应该检查每一个然后将颜色更改为红色表示没有蓝色表示是。

  <html>
<head>
<title>colorme</title>



<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2 /jquery.js"></script>
<script>
$(document).ready(function(){


$(".test").each(function(){

var title = $(this).find('.taskName').attr("title");
if(title =="yes") {
$('div.taskName').css('color','blue');

}
else if(title =="no") {
$('div.taskName').css('color','red');

}
});

});


</script>

</head>
<body>
<div class="test">
<div class="taskName" title="yes">this should be blue</div>
<div class="taskName" title="no">this should not be blue</div>
<div class="taskName" title="yes">this should be blue</div>
<div class="taskName" title="no">this should not be blue</div>
</div>


</body>

</html>

最佳答案

像这样尝试:

var $div = $('div.taskName');
$div.filter('[title=yes]').css('color', 'blue');
$div.filter('[title=no]').css('color', 'red');

关于jquery - 使用属性 'title' 更改 css 项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14698461/

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