我想更改特定类的名称。我试过几种方法,但我还是失败了。
var tdObj = $ ("div.event-list-item") .parents (). addClass ("disable");
似乎是一个问题。
function endTimeCheck() {
$("span[name='betStatus']" ).each( function(){
var play_timestamp = parseInt( $( this ).attr( "timestamp" ) );
var countdown = play_timestamp - timestamp - 32700;
if( countdown <= 0 )
{
if ($( this ).css("color") != "red") {
$( this ).css( "color", "red" ).text( "Close" );
// An error occurs.
var tdObj = $( "div.event-list-item" ).parents().addClass("disable");
// An error occurs.
}
}
HTML是:第6行:如果条件正确,我想更改div类名。
before: <div class="event-list-item ">
after: <div class="event-list-item disable">
<div class="bet_list">
<div class="event-list-date">
<img src="/img/country/icon_ITA D1.png"> ITA D1
</div>
<div class="event-list">
<div class="event-list-item ">
<div class="event-list-table">
<div class="event-list-row" data-eventid="430046,2.30,3.20,3.30">
<div class="elc elc-time">
10-22 03:45
</div>
<div class="elc bet-trigger" id="430046_1">CFC
<div class="elc-odds"><span class="o">2.30</span>
</div>
</div>
<div class="elc bet-trigger elc--draw" id="430046_0">
<div class="elc-odds"><span class="o">3.20</span></div>
</div>
<div class="elc bet-trigger elc--right" id="430046_2">
FC 1909
<div class="elc-odds"><span class="o">3.30</span></div>
</div>
<div class="elc elc-more">
<div class="elc-more-count" data-id="2588380">
<span name="betStatus" timestamp="1508643900" style="color: red; font-weight: bold;">Close</span> +2
</div>
<i class="fa fa-chevron-up"></i>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
首先,我不知道你想要去哪里,因为包括html,css,jquery的东西尝试使用SO的片段,所以我们可能会更有帮助。 那个说,我注意到你试图用它的颜色来测试一个元素,据我所知,这不是一个很好的方法,为什么呢?因为主要的浏览器总是以rgb或rgba格式返回颜色,你所做的可能适用于旧的浏览器,我建议你做的是采取那种风格并将其包装在css类中,并检查是否存在css课,我不知道你想做什么,所以我只是称之为 .closed
function endTimeCheck() {
$("span[name='betStatus']").each(function() {
var $span = $(this);
var play_timestamp = parseInt( $span.attr( "timestamp" ) );
var timestamp = 1508643900; // i presume you declared this somewhere in your script
var countdown = (play_timestamp - timestamp) - 32700;
if( countdown <= 0 ) {
if (! $span.hasClass('closed')) {
$span.css("color", "red").text( "Close" );
var tdObj = $span.parents('.event-list-item').addClass("disable");
}
}
});
}
endTimeCheck();
.closed {
color: red;
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Your title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div class="bet_list">
<div class="event-list-date">
</div>
<div class="event-list">
<div class="event-list-item ">
<div class="event-list-table">
<div class="event-list-row" data-eventid="430046,2.30,3.20,3.30">
<div class="elc elc-time">
10-22 03:45
</div>
<div class="elc bet-trigger" id="430046_1">CFC
<div class="elc-odds"><span class="o">2.30</span>
</div>
</div>
<div class="elc bet-trigger elc--draw" id="430046_0">
<div class="elc-odds"><span class="o">3.20</span></div>
</div>
<div class="elc bet-trigger elc--right" id="430046_2">
FC 1909
<div class="elc-odds"><span class="o">3.30</span></div>
</div>
<div class="elc elc-more">
<div class="elc-more-count" data-id="2588380">
<span name="betStatus" timestamp="1508643900" class="closed">Close</span> +2
</div>
<i class="fa fa-chevron-up"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>