开发者

Uncaught TypeError [closed]

开发者_开发知识库Closed. This question needs debugging details. It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.

Closed 7 years ago.

Improve this question

Can anyone explain what is theses errors?

Uncaught TypeError: Cannot set property 'innerHTML' of null

Uncaught TypeError: Cannot read property 'style' of null

Uncaught SyntaxError: Unexpected token ILLEGAL

Uncaught TypeError: Object # has no method 'dispatchEvent'

This is my test Website


At some point in the page you have:

function display_price(price, oid)
{
    ...

    element = document.getElementById(oid);
    if (valor != 'NaN' && valor != null && valor != '')
    {
       element.innerHTML = valor + money_simbol;

The last line is causing the error because element is null. You should add a condition to the if(): that is, change this line:

if (valor != 'NaN' && valor != null && valor != '')

to this:

if (element && valor != 'NaN' && valor != null && valor != '')

In other words, it's a good practice to always check the return value of a function before accessing its properties.


You call the function display_price passing it ID of span that does not yet exist.

Change this line: (appears twice in your code)

display_price('510', 'products_price_id');

To this instead:

window.onload = function() {
   display_price('510', 'products_price_id');
};

This will wait until the page loads before trying to find the element, thus solve your errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜