JS Uncaught TypeError: Cannot read property ‘indexOf‘ of null问题解决

it2024-04-02  70

问题描述:

Uncaught TypeError: Cannot read property 'indexOf' of null

问题分析:

使用indexOf()的变量为null。

问题解决:

1、使用indexOf()之前,先判断使用indexOf()的变量是否为null。

var str=null; if(str!=null&&str.indexOf("1")>-1){ alert("包含1"); }

2、检查使用indexOf()的变量为什么会为null。

最新回复(0)