admin管理员组

文章数量:1023213

I have this JavaScript block code:

var trows = table.getElementsByTagName('tbody')[0].rows;  
for(var j = ((pageNumber - 1) * rowsPerPage); j < ((pageNumber) * rowsPerPage); j++)
{
  trows[j].style.display = 'table-row';
}

Before I implement this row:

 trows[j].style.display = 'table-row';

I need to check if table row with scpecific index exists.

How to check in JavaScript if table row with specific index exist?

I have this JavaScript block code:

var trows = table.getElementsByTagName('tbody')[0].rows;  
for(var j = ((pageNumber - 1) * rowsPerPage); j < ((pageNumber) * rowsPerPage); j++)
{
  trows[j].style.display = 'table-row';
}

Before I implement this row:

 trows[j].style.display = 'table-row';

I need to check if table row with scpecific index exists.

How to check in JavaScript if table row with specific index exist?

Share Improve this question edited Nov 11, 2014 at 15:37 Kashif Umair Liaqat 1,0741 gold badge19 silver badges27 bronze badges asked Nov 11, 2014 at 15:18 MichaelMichael 13.6k59 gold badges170 silver badges315 bronze badges 3
  • Is jQuery an option? – puelo Commented Nov 11, 2014 at 15:20
  • 2 trows[j].value != undefined – Mahmoud.Eskandari Commented Nov 11, 2014 at 15:22
  • No I don't use jQuery – Michael Commented Nov 11, 2014 at 15:27
Add a ment  | 

2 Answers 2

Reset to default 5

Since undefined is falsey, you can just do this:

if (trows[j]) {
    trows[j].style.display = 'table-row';
}
if(typeof trows[j] !== 'undefined') {
    trows[j].style.display = 'table-row';
}

You can check if the type is undefined.

I have this JavaScript block code:

var trows = table.getElementsByTagName('tbody')[0].rows;  
for(var j = ((pageNumber - 1) * rowsPerPage); j < ((pageNumber) * rowsPerPage); j++)
{
  trows[j].style.display = 'table-row';
}

Before I implement this row:

 trows[j].style.display = 'table-row';

I need to check if table row with scpecific index exists.

How to check in JavaScript if table row with specific index exist?

I have this JavaScript block code:

var trows = table.getElementsByTagName('tbody')[0].rows;  
for(var j = ((pageNumber - 1) * rowsPerPage); j < ((pageNumber) * rowsPerPage); j++)
{
  trows[j].style.display = 'table-row';
}

Before I implement this row:

 trows[j].style.display = 'table-row';

I need to check if table row with scpecific index exists.

How to check in JavaScript if table row with specific index exist?

Share Improve this question edited Nov 11, 2014 at 15:37 Kashif Umair Liaqat 1,0741 gold badge19 silver badges27 bronze badges asked Nov 11, 2014 at 15:18 MichaelMichael 13.6k59 gold badges170 silver badges315 bronze badges 3
  • Is jQuery an option? – puelo Commented Nov 11, 2014 at 15:20
  • 2 trows[j].value != undefined – Mahmoud.Eskandari Commented Nov 11, 2014 at 15:22
  • No I don't use jQuery – Michael Commented Nov 11, 2014 at 15:27
Add a ment  | 

2 Answers 2

Reset to default 5

Since undefined is falsey, you can just do this:

if (trows[j]) {
    trows[j].style.display = 'table-row';
}
if(typeof trows[j] !== 'undefined') {
    trows[j].style.display = 'table-row';
}

You can check if the type is undefined.

本文标签: How to check in JavaScript if table row with specific index existStack Overflow