当前位置: 动力学知识库 > 问答 > 编程问答 >

Javascript: replace() function not working in Mac safari

问题描述:

I have the below set of code to replace specific tags from string.It's not working in Mac safari but working properly in windows chrome and firefox.

Error: TypeError: 'undefined' is not an object (evaluating 'n.innerHTML.replace')

html_data = html_data.replace(/para/g, "p");

html_data = html_data.replace(/useful/g, "span");

html_data = html_data.replace(/extra_info/g, "span");

网友答案:

Error: TypeError: 'undefined' is not an object (evaluating 'n.innerHTML.replace')

this means that either n is undefined, or n.innerHTML is undefined. It is not about replace function. Since you did not submit the full code, can you check which one is undefined?

网友答案:

Your error message indicates that you are trying to call the .replace method of an undefined object.

Therefore your problem is that either n or n.innerHTML is undefined (for reasons that cannot be discerned given the limited information we have) and nothing to do with .replace at all.

分享给朋友:
您可能感兴趣的文章:
随机阅读: