Uncaught TypeError: Cannot call method 'replace' of undefined 的解决

 
Uncaught TypeError: Cannot call method 'replace' of undefined 的解决

1. js代码
	var rip = $("#RSIP").val(); 
	rip = rip.replace(/\r|\n/g,":");

	报错 Uncaught TypeError: Cannot call method 'replace' of undefined
2. 代码更改为
	var rip = $("#RSIP").val();
	console.log(rip)
	rip = rip.replace(/\r|\n/g,":");
	得到输出为
	Undefined editTask:28
	Uncaught TypeError: Cannot call method 'replace' of undefined 
3.可见 rip为未定义,在html中搜 RSIP,发现
	   
	可见的确未定义  
4.更改为

	   
	之后,代码正常

	也可将js代码修改为
	var rip = $("textarea[name='RSIP']").val();
	去取得对应的元素数据
5.结论:发现难以判断的错误时,多使用 console.log 

你可能感兴趣的:(Uncaught TypeError: Cannot call method 'replace' of undefined 的解决)