Как выполнить значение из < td > элемент

Поскольку некоторые люди связывают это с почти любым потоком, где результат вычисления равен 0, я добавляю это как решение, так как не все остальные ответы относятся к сценариям случая.

Концепция необходимости выполнять вычисления по различным типам, чтобы получить этот тип в качестве результата, однако выше только показывает «десятичный» и использует его короткую форму, такую ​​как 18m, как одну из переменных, подлежащих вычислению.

// declare and define initial variables.
int x = 0;
int y = 100;

// set the value of 'x'    
x = 44;

// Results in 0 as the whole number 44 over the whole number 100 is a 
// fraction less than 1, and thus is 0.
Console.WriteLine( (x / y).ToString() );

// Results in 0 as the whole number 44 over the whole number 100 is a 
// fraction less than 1, and thus is 0. The conversion to double happens 
// after the calculation has been completed, so technically this results
// in 0.0
Console.WriteLine( ((double)(x / y)).ToString() );

// Results in 0.44 as the variables are cast prior to calculating
// into double which allows for fractions less than 1.
Console.WriteLine( ((double)x / (double)y).ToString() );
0
задан marc_s 16 January 2019 в 15:17
поделиться

2 ответа

Вы можете перебрать коллекцию HTML, используя Array.prototype.filter, вызываемую с коллекцией HTML в качестве контекста.

Следующий фрагмент может быть полезным:

var cells = document.getElementById("calendar-dates").getElementsByTagName("td");
var current_date = d.getDate();
var matchingElement = Array.prototype.filter.call(cells, function(cell) {
  return +current_date === +cell.textContent;
})[0];
matchingElement.style.backgroundColor = 'red';
0
ответ дан antonku 16 January 2019 в 15:17
поделиться

По сути, вы должны проверить, совпадает ли текущая дата, которую вы вставляете, с сегодняшней (new Date()).

function isToday(day, month, year){
  const today = new Date();
  return today.getDate() === day && today.getMonth() === month &&     today.getFullYear()===year;
}

https://codepen.io/kwiniarski97/pen/magPKV?editors=1111

это можно сделать другими способами, это только один

0
ответ дан karoluS 16 January 2019 в 15:17
поделиться
Другие вопросы по тегам:

Похожие вопросы: