| |

VerySource

 Forgot password?
 Register
Search
View: 873|Reply: 4

Determine if the object exists! !!

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-30 16:40:01
| Show all posts |Read mode
for (var i = 0; i <colCount; i ++) {
 var classname = event.srcElement.parentElement.cells [i] .className + "2";
    event.srcElement.parentElement.cells [i] .className = classname;
}

Hello, I would like to ask you the old question. As above, put the results of the query from the database in the table. If the cursor points to one row, its CLASSNAME will change, and event.srcElement refers to one of the columns pointed to, event .srcElement.parentElement is its row, then iterate through all the columns in this row, and change the CLASSNAME of its column together, but sometimes it will prompt event.srcElement.parentElement.cells is empty or not an object, the page is still the starting page How could it not exist? Please enlighten me! !! !!
Now I want to add a judgment condition to judge whether event.srcElement.parentElement.cells [i] exists, how should I write it?
event.srcElement.parentElement.cells [i]! = null right
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-3-7 16:45:01
| Show all posts
Use typeof to determine if a variable is an object

Such as
var a = new object ();
var b = 'string';
alert (typeof a == 'object') // return true
alert (typeof b == 'object') // return false

Should understand
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Turkey

 Author| Post time: 2020-3-14 10:45:01
| Show all posts
His tip: It is empty or not an object. After adding the judgment statement upstairs, it still prompts an error, and I ca n’t catch the error using try {} catch (e) {}. It ’s strange, do n’t call this public code Time, the page is good, after calling, the page is good at the beginning, and it will be prompted after a while, but my other pages call this public code is correct, is there any restrictions on event.srcElement.parentElement ?
Reply

Use magic Report

0

Threads

20

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-3-14 12:45:02
| Show all posts
typeof a == 'object'
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-3-16 15:30:01
| Show all posts
Thank you, it was solved, it was solved, the master helped me solve it, and added an additional judgment statement event.srcElement.parentElement.cells! = null
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list